Python multiprocessing.managers 模块,BaseManager() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用multiprocessing.managers.BaseManager()

项目:entity-linker    作者:seucs    | 项目源码 | 文件源码
def work(server_addr):
    # ?????
    from database.db import baidu_db

    # ????
    class QueueManager(BaseManager):
        pass
    QueueManager.register('get_task_queue')
    QueueManager.register('get_result_queue')
    print('Connect to server %s...' % server_addr)
    m = QueueManager(address=(server_addr, 5000), authkey='abc')
    m.connect()
    task = m.get_task_queue()
    result = m.get_result_queue()


    while True:
        try:
            (nn, ii, jj, name) = task.get(timeout=100)
            candidates = baidu_db.getCandidates(name)
            result.put((nn, ii, jj, candidates))
        except Queue.Empty:
            print 'queue is empty'
            continue
    print 'worker exit.'
项目:ml-utils    作者:LinxiFan    | 项目源码 | 文件源码
def __init__(self, url, port, authkey=b'abracadabra'):
        class _MyManager(mgr.BaseManager):
            pass
        self._MyManager = _MyManager
        self._server_args = ((url, port), authkey)
        self._server = None
        self._client_connected = False
        self.registry = set()
        # sharing synced objects with special proxies
        self._special_vars = {dtype: {} for dtype in self.SPECIAL_PROXIES}
        ProcessSharing._generate_add_special()