當前位置: 首頁>>代碼示例>>Python>>正文


Python managers.SyncManager方法代碼示例

本文整理匯總了Python中multiprocessing.managers.SyncManager方法的典型用法代碼示例。如果您正苦於以下問題:Python managers.SyncManager方法的具體用法?Python managers.SyncManager怎麽用?Python managers.SyncManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在multiprocessing.managers的用法示例。


在下文中一共展示了managers.SyncManager方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Manager

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def Manager():
    '''
    Returns a manager associated with a running server process

    The managers methods such as `Lock()`, `Condition()` and `Queue()`
    can be used to create shared objects.
    '''
    from multiprocessing.managers import SyncManager
    m = SyncManager()
    m.start()
    return m

#brython fix me
#def Pipe(duplex=True):
#    '''
#    Returns two connection object connected by a pipe
#    '''
#    from multiprocessing.connection import Pipe
#    return Pipe(duplex) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:21,代碼來源:__init__.py

示例2: Manager

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def Manager():
    '''
    Returns a manager associated with a running server process

    The managers methods such as `Lock()`, `Condition()` and `Queue()`
    can be used to create shared objects.
    '''
    from multiprocessing.managers import SyncManager
    m = SyncManager()
    m.start()
    return m 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:__init__.py

示例3: _manticore_multiprocessing

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def _manticore_multiprocessing(self):
        def raise_signal():
            signal.signal(signal.SIGINT, signal.SIG_IGN)

        self._worker_type = WorkerProcess
        # This is the global manager that will handle all shared memory access
        # See. https://docs.python.org/3/library/multiprocessing.html#multiprocessing.managers.SyncManager
        self._manager = SyncManager()
        self._manager.start(raise_signal)
        # The main manticore lock. Acquire this for accessing shared objects
        # THINKME: we use the same lock to access states lists and shared contexts
        self._lock = self._manager.Condition()
        self._killed = self._manager.Value(bool, False)
        self._running = self._manager.Value(bool, False)
        # List of state ids of States on storage
        self._ready_states = self._manager.list()
        self._terminated_states = self._manager.list()
        self._busy_states = self._manager.list()
        self._killed_states = self._manager.list()
        self._shared_context = self._manager.dict()
        self._context_value_types = {list: self._manager.list, dict: self._manager.dict}

    # Decorators added first for convenience. 
開發者ID:trailofbits,項目名稱:manticore,代碼行數:25,代碼來源:manticore.py

示例4: make_worker_manager

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def make_worker_manager(ip, port, authkey):
    """ Create a manager for a client. This manager connects to a server on the
        given address and exposes the get_job_q and get_result_q methods for
        accessing the shared queues from the server.
        Return a manager object.
    """
    class ServerQueueManager(SyncManager):
        pass

    ServerQueueManager.register('get_job_q')
    ServerQueueManager.register('get_result_q')

    manager = ServerQueueManager(address=(ip, port), authkey=authkey)
    manager.connect()

    logging.info("Worker connected to {:s}:{:d}".format(ip, port))
    return manager 
開發者ID:soodoku,項目名稱:get-weather-data,代碼行數:19,代碼來源:worker.py

示例5: _multiprocessing_transform

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def _multiprocessing_transform():
    module = astroid.parse('''
    from multiprocessing.managers import SyncManager
    def Manager():
        return SyncManager()
    ''')
    if not PY34:
        return module

    # On Python 3.4, multiprocessing uses a getattr lookup inside contexts,
    # in order to get the attributes they need. Since it's extremely
    # dynamic, we use this approach to fake it.
    node = astroid.parse('''
    from multiprocessing.context import DefaultContext, BaseContext
    default = DefaultContext()
    base = BaseContext()
    ''')
    try:
        context = next(node['default'].infer())
        base = next(node['base'].infer())
    except exceptions.InferenceError:
        return module

    for node in (context, base):
        for key, value in node.locals.items():
            if key.startswith("_"):
                continue

            value = value[0]
            if isinstance(value, astroid.FunctionDef):
                # We need to rebound this, since otherwise
                # it will have an extra argument (self).
                value = astroid.BoundMethod(value, node)
            module[key] = value
    return module 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:37,代碼來源:brain_multiprocessing.py

示例6: _multiprocessing_transform

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def _multiprocessing_transform():
    module = astroid.parse(
        """
    from multiprocessing.managers import SyncManager
    def Manager():
        return SyncManager()
    """
    )
    if not PY34:
        return module

    # On Python 3.4, multiprocessing uses a getattr lookup inside contexts,
    # in order to get the attributes they need. Since it's extremely
    # dynamic, we use this approach to fake it.
    node = astroid.parse(
        """
    from multiprocessing.context import DefaultContext, BaseContext
    default = DefaultContext()
    base = BaseContext()
    """
    )
    try:
        context = next(node["default"].infer())
        base = next(node["base"].infer())
    except exceptions.InferenceError:
        return module

    for node in (context, base):
        for key, value in node.locals.items():
            if key.startswith("_"):
                continue

            value = value[0]
            if isinstance(value, astroid.FunctionDef):
                # We need to rebound this, since otherwise
                # it will have an extra argument (self).
                value = astroid.BoundMethod(value, node)
            module[key] = value
    return module 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:41,代碼來源:brain_multiprocessing.py

示例7: __init__

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def __init__(self, parallelism: int = PARALLELISM):
        super().__init__(parallelism=parallelism)
        self.manager: Optional[SyncManager] = None
        self.result_queue: Optional['Queue[TaskInstanceStateType]'] = None
        self.workers: List[QueuedLocalWorker] = []
        self.workers_used: int = 0
        self.workers_active: int = 0
        self.impl: Optional[Union['LocalExecutor.UnlimitedParallelism',
                                  'LocalExecutor.LimitedParallelism']] = None 
開發者ID:apache,項目名稱:airflow,代碼行數:11,代碼來源:local_executor.py

示例8: _ignore_sigint_manager

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def _ignore_sigint_manager():
    """Context-managed SyncManager which ignores SIGINT interrupt signals."""
    manager = SyncManager()
    try:
        manager.start(_ignore_sigint_initializer)
        yield manager
    finally:
        manager.shutdown() 
開發者ID:matt-graham,項目名稱:mici,代碼行數:10,代碼來源:samplers.py

示例9: _receive

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def _receive(self):
        while True:
            # If we don't have any listeners, we don't want to be checking
            # the queue. In particular, since this is a daemon thread, it
            # will keep running up until the process exits, and at that time
            # the queue object can become unreliable because it's managed by
            # a SyncManager that depends on a separate process. This listener
            # check makes sure we're only using the queue during an actual
            # Flow.get call.
            # See here for what happens if we don't have this check:
            # https://github.com/square/bionic/issues/161
            self._event_has_listeners.wait()

            if self._queue.empty():
                self._event_queue_is_empty.set()
            else:
                self._event_queue_is_empty.clear()

            try:
                record = self._queue.get(timeout=0.05)
            except queue.Empty:  # Nothing to receive from the queue.
                continue

            logger = logging.getLogger(record.name)
            try:
                if logger.isEnabledFor(record.levelno):
                    logger.handle(record)
            except (BrokenPipeError, EOFError):
                break
            except Exception as e:
                logger = logging.getLogger()
                try:
                    logger.warn("exception while logging ", e)
                except (BrokenPipeError, EOFError):
                    break
                except Exception:
                    traceback.print_exc(file=sys.stderr) 
開發者ID:square,項目名稱:bionic,代碼行數:39,代碼來源:executor.py

示例10: make_server_manager

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def make_server_manager(port, authkey):
    job_q = queue.Queue()
    result_q = queue.Queue()

    class JobQueueManager(SyncManager):
        pass

    JobQueueManager.register('get_job_q', callable=lambda: job_q)
    JobQueueManager.register('get_result_q', callable=lambda: result_q)

    manager = JobQueueManager(address=('', port), authkey=authkey)
    manager.start()
    print('Server started at port %s' % port)
    return manager 
開發者ID:eliben,項目名稱:code-for-blog,代碼行數:16,代碼來源:distributed_factor.py

示例11: make_client_manager

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def make_client_manager(ip, port, authkey):
    class ServerQueueManager(SyncManager):
        pass

    ServerQueueManager.register('get_job_q')
    ServerQueueManager.register('get_result_q')

    manager = ServerQueueManager(address=(ip, port), authkey=authkey)
    manager.connect()

    print('Client connected to %s:%s' % (ip, port))
    return manager 
開發者ID:eliben,項目名稱:code-for-blog,代碼行數:14,代碼來源:distributed_factor.py

示例12: _multiprocessing_managers_transform

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def _multiprocessing_managers_transform():
    return astroid.parse('''
    import array
    import threading
    import multiprocessing.pool as pool

    import six

    class Namespace(object):
        pass

    class Value(object):
        def __init__(self, typecode, value, lock=True):
            self._typecode = typecode
            self._value = value
        def get(self):
            return self._value
        def set(self, value):
            self._value = value
        def __repr__(self):
            return '%s(%r, %r)'%(type(self).__name__, self._typecode, self._value)
        value = property(get, set)

    def Array(typecode, sequence, lock=True):
        return array.array(typecode, sequence)

    class SyncManager(object):
        Queue = JoinableQueue = six.moves.queue.Queue
        Event = threading.Event
        RLock = threading.RLock
        BoundedSemaphore = threading.BoundedSemaphore
        Condition = threading.Condition
        Barrier = threading.Barrier
        Pool = pool.Pool
        list = list
        dict = dict
        Value = Value
        Array = Array
        Namespace = Namespace
        __enter__ = lambda self: self
        __exit__ = lambda *args: args
        
        def start(self, initializer=None, initargs=None):
            pass
        def shutdown(self):
            pass
    ''') 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:49,代碼來源:brain_multiprocessing.py

示例13: _multiprocessing_managers_transform

# 需要導入模塊: from multiprocessing import managers [as 別名]
# 或者: from multiprocessing.managers import SyncManager [as 別名]
def _multiprocessing_managers_transform():
    return astroid.parse(
        """
    import array
    import threading
    import multiprocessing.pool as pool

    import six

    class Namespace(object):
        pass

    class Value(object):
        def __init__(self, typecode, value, lock=True):
            self._typecode = typecode
            self._value = value
        def get(self):
            return self._value
        def set(self, value):
            self._value = value
        def __repr__(self):
            return '%s(%r, %r)'%(type(self).__name__, self._typecode, self._value)
        value = property(get, set)

    def Array(typecode, sequence, lock=True):
        return array.array(typecode, sequence)

    class SyncManager(object):
        Queue = JoinableQueue = six.moves.queue.Queue
        Event = threading.Event
        RLock = threading.RLock
        BoundedSemaphore = threading.BoundedSemaphore
        Condition = threading.Condition
        Barrier = threading.Barrier
        Pool = pool.Pool
        list = list
        dict = dict
        Value = Value
        Array = Array
        Namespace = Namespace
        __enter__ = lambda self: self
        __exit__ = lambda *args: args

        def start(self, initializer=None, initargs=None):
            pass
        def shutdown(self):
            pass
    """
    ) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:51,代碼來源:brain_multiprocessing.py


注:本文中的multiprocessing.managers.SyncManager方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。