Python multiprocessing.managers.BaseManager() Examples

The following are 7 code examples of multiprocessing.managers.BaseManager(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module multiprocessing.managers , or try the search function .
Example #1
Source File: remotequeue.py    From burgundy with MIT License 5 votes vote down vote up
def get(ip, authkey):
    ''' gets a remote queue on another ip '''
    class RManager(BaseManager):
        ''' manager which connects to a remote queue '''
        pass
    RManager.register('getQueue')
    current_manager = RManager(address=(ip,PORT), authkey=authkey)
    current_manager.connect()
    return current_manager.getQueue() 
Example #2
Source File: remotequeue.py    From burgundy with MIT License 5 votes vote down vote up
def make(authkey, public=True):
    ''' makes a remote queue and returns it '''
    class QManager(BaseManager):
        ''' manager of a remote queue '''
        pass
    queue = Queue()
    QManager.register('getQueue', callable=lambda:queue)
    ip = '0.0.0.0' if public else 'localhost'
    qm = QManager(address=(ip, PORT), authkey=authkey)
    qm.start()
    tokens = [random.choice('abcde') for x in range(14)]
    random_token = 'x'.join(tokens)
    globals()['raNdDOmHAkkC82492'] = qm
    return queue 
Example #3
Source File: remotequeue.py    From burgundy with MIT License 5 votes vote down vote up
def get(ip, authkey):
    ''' gets a remote queue on another ip '''
    class RManager(BaseManager):
        ''' manager which connects to a remote queue '''
        pass
    RManager.register('getQueue')
    current_manager = RManager(address=(ip,PORT), authkey=authkey)
    current_manager.connect()
    return current_manager.getQueue() 
Example #4
Source File: remotequeue.py    From burgundy with MIT License 5 votes vote down vote up
def make(authkey, public=True):
    ''' makes a remote queue and returns it '''
    class QManager(BaseManager):
        ''' manager of a remote queue '''
        pass
    queue = Queue()
    QManager.register('getQueue', callable=lambda:queue)
    ip = '0.0.0.0' if public else 'localhost'
    qm = QManager(address=(ip, PORT), authkey=authkey)
    qm.start()
    tokens = [random.choice('abcde') for x in range(14)]
    random_token = 'x'.join(tokens)
    globals()['raNdDOmHAkkC82492'] = qm
    return queue 
Example #5
Source File: remotequeue.py    From burgundy with MIT License 5 votes vote down vote up
def get(ip, authkey):
    ''' gets a remote queue on another ip '''
    class RManager(BaseManager):
        ''' manager which connects to a remote queue '''
        pass
    RManager.register('getQueue')
    current_manager = RManager(address=(ip,PORT), authkey=authkey)
    current_manager.connect()
    return current_manager.getQueue() 
Example #6
Source File: manager_in_multiprocess.py    From deepdiy with MIT License 5 votes vote down vote up
def main():
    manager = BaseManager()
    manager.register('Employee', Employee)
    manager.start()
    em = manager.Employee('zhangsan', 1000)
    lock = Lock()
    proces = [Process(target=func1, args=(em, lock)) for i in range(10)]
    for p in proces:
        p.start()
    for p in proces:
        p.join()
    print((em.getPay())) 
Example #7
Source File: distributed.py    From neat-python with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _get_manager_class(self, register_callables=False):
        """
        Returns a new 'Manager' subclass with registered methods.
        If 'register_callable' is True, defines the 'callable' arguments.
        """

        class _EvaluatorSyncManager(managers.BaseManager):
            """
            A custom BaseManager.
            Please see the documentation of `multiprocessing` for more
            information.
            """
            pass

        inqueue = queue.Queue()
        outqueue = queue.Queue()
        namespace = Namespace()

        if register_callables:
            _EvaluatorSyncManager.register(
                "get_inqueue",
                callable=lambda: inqueue,
                )
            _EvaluatorSyncManager.register(
                "get_outqueue",
                callable=lambda: outqueue,
                )
            _EvaluatorSyncManager.register(
                "get_state",
                callable=self._get_secondary_state,
                )
            _EvaluatorSyncManager.register(
                "set_state",
                callable=lambda v: self._secondary_state.set(v),
                )
            _EvaluatorSyncManager.register(
                "get_namespace",
                callable=lambda: namespace,
                )
        else:
            _EvaluatorSyncManager.register(
                "get_inqueue",
                )
            _EvaluatorSyncManager.register(
                "get_outqueue",
                )
            _EvaluatorSyncManager.register(
                "get_state",
                )
            _EvaluatorSyncManager.register(
                "set_state",
                )
            _EvaluatorSyncManager.register(
                "get_namespace",
                )
        return _EvaluatorSyncManager