semvec/pypi-packages huggingface dataset:
fast-ipc 0.0.8
fast_ipc: Inter-Process Communication , muti Process Woker works by share memory.
License: Apache 2.0
Requires Python: >=3, <4
Keywords: fast_ipc,ipc,ipc mq,fast-ipc,process ipc

fast_ipc: Inter-Process Communication , muti Process Woker works by share memory.

```py
# -*- coding: utf-8 -*-
# @Time    : 2021/11/23 9:35

'''
recommended system linux and python >= 3.8
    recommended linux
    python 3.8

Do not recommended run in windows , it will report an error as follow
    RuntimeError:
            An attempt has been made to start a new process before the
            current process has finished its bootstrapping phase.

'''

import multiprocessing
import time,os
from fast_ipc import fast_ipc,ProcessWorker
class My_worker(ProcessWorker):
    def __init__(self,config,*args,**kwargs):
        super(My_worker,self).__init__(*args,**kwargs)
        #config info , use by yourself

        self._logger.info('Process id {}, group name {} ,shm name {}'.format(self._idx,self._group_name,self._shm_name))
        self._logger.info(config)
        self.config = config


    #Process begin trigger this func
    def run_begin(self):
        self._logger.info('worker pid {}...'.format(os.getpid()))
        self.handle = None
        pass

    # Process end trigger this func
    def run_end(self):
        if self.handle is not None:
            pass

    #any data put will trigger this func
    def run_once(self,request_data):
        #process request_data
        if isinstance(request_data,dict):
            request_data['b']  = 200
        if self.handle is not None:
            #do some thing
            pass
        return request_data


if __name__ == '__main__':
    config = {
        "anything" : "anything",
        "cof": 'fonf',
        "aa": 100
    }

    evt_quit = multiprocessing.Manager().Event()
    instance = fast_ipc()

    #group_name 为共享内存组名,需唯一
    #manager is an agent  and act as a load balancing
    #worker is real doing your work
    instance.start(
        CLS_worker=My_worker,
        worker_args=(config,),# must be tuple
        worker_num=4,#number of worker Process
        manager_num=2,#number of agent Process
        group_name='serving_shm',# share memory name
        shm_size=1*1024*1024, # share memory size
        queue_size=20,# recv queue size
        is_log_time=True # whether log compute time
    )

    #demo produce and consume message , you can process by http
    time.sleep(1)
    for i in range(1):
        print('produce message')
        data = {"a" : 100}
        instance.put(data)

        print('get process result')
        data = instance.get()
        print(data)

    try:
        instance.join()
    except Exception as e:
        print(e)
        evt_quit.set()
        instance.terminate()

    del evt_quit
```