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


Python multiprocessing.managers方法代碼示例

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


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

示例1: __stop__

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def __stop__(self):
        self._running = False
        try:  # try/except needed only for python2 compatibility
            # end daemon threads which distribute the work load
            for th, q1, q2 in self.threads:
                q1.put(None)
                th.join()
            delattr(self, 'threads')
            # end managers which handle the convolvers
            delattr(self, 'conv_handlers')
            for m in self.managers:
                m.shutdown()
            delattr(self, 'managers')
        except AttributeError:
            pass
        atexit.unregister(self.__stop__) 
開發者ID:dkriegner,項目名稱:xrayutilities,代碼行數:18,代碼來源:powder.py

示例2: test_import

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def test_import(self):
        modules = [
            'multiprocessing', 'multiprocessing.connection',
            'multiprocessing.heap', 'multiprocessing.managers',
            'multiprocessing.pool', 'multiprocessing.process',
            'multiprocessing.synchronize', 'multiprocessing.util'
            ]

        if HAS_REDUCTION:
            modules.append('multiprocessing.reduction')

        if c_int is not None:
            # This module requires _ctypes
            modules.append('multiprocessing.sharedctypes')

        for name in modules:
            __import__(name)
            mod = sys.modules[name]

            for attr in getattr(mod, '__all__', ()):
                self.assertTrue(
                    hasattr(mod, attr),
                    '%r does not have attribute %r' % (mod, attr)
                    )

#
# Quick test that logging works -- does not test logging output
# 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:30,代碼來源:test_multiprocessing.py

示例3: test_manager_initializer

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def test_manager_initializer(self):
        m = multiprocessing.managers.SyncManager()
        self.assertRaises(TypeError, m.start, 1)
        m.start(initializer, (self.ns,))
        self.assertEqual(self.ns.test, 1)
        m.shutdown() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_multiprocessing.py

示例4: process_manager

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def process_manager(self):
        if self._process_manager is None:
            self._process_manager = multiprocessing.managers.SyncManager()
            self._process_manager.start(_manager_initializer)
        return self._process_manager 
開發者ID:boto,項目名稱:botoflow,代碼行數:7,代碼來源:multiprocessing_executor.py

示例5: __init__

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def __init__(self):
        self._memories = {}
        self._manager = multiprocessing.managers.SyncManager()

        self._locks = set()
        self._locks_queues = {} 
開發者ID:python-botogram,項目名稱:botogram,代碼行數:8,代碼來源:shared.py

示例6: test_manager_initializer

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def test_manager_initializer(self):
        m = multiprocessing.managers.SyncManager()
        self.assertRaises(TypeError, m.start, 1)
        m.start(initializer, (self.ns,))
        self.assertEqual(self.ns.test, 1)
        m.shutdown()
        m.join() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:_test_multiprocessing.py

示例7: start

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def start(self, initializer=None, initargs=()):
            '''
            Spawn a server process for this manager object
            '''
            assert self._state.value == multiprocessing.managers.State.INITIAL

            if initializer is not None and not hasattr(initializer,
                                                       '__call__'):
                raise TypeError('initializer must be a callable')

            # pipe over which we will retrieve address of server
            reader, writer = multiprocessing.Pipe(duplex=False)

            # spawn process which runs a server
            self._process = multiprocessing.Process(
                target=type(self)._run_server,
                args=(self._registry, self._address, self._authkey,
                      self._serializer, writer, initializer, initargs),
            )
            ident = ':'.join(str(i) for i in self._process._identity)
            self._process.name = type(self).__name__ + '-' + ident
            self._process.start()

            # get address of server
            writer.close()
            self._address = reader.recv()
            reader.close()

            # register a finalizer
            self._state.value = multiprocessing.managers.State.STARTED
            self.shutdown = multiprocessing.util.Finalize(
                self, type(self)._finalize_manager,
                args=(self._process, self._address, self._authkey,
                      self._state, self._Client),
                exitpriority=0
            ) 
開發者ID:gkrizek,項目名稱:bash-lambda-layer,代碼行數:38,代碼來源:compat.py

示例8: _init_multiprocessing

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def _init_multiprocessing(self):
        """
        initialize multiprocessing for powder pattern calculation
        """
        # The structure of the multiprocessing code is as follows:
        # There are nproc "manager"s which handle the actual convolver code.
        # Additionally there are 4 daemon threads which listen for work to be
        # distributed to the managers.
        np = config.NTHREADS
        self.nproc = np if np != 0 else multiprocessing.cpu_count()
        self.chunks = chunkify(list(self.data), self.nproc)
        self.next_proc = len(self.data) % self.nproc
        manager.register("conv", convolver_handler)
        self.managers = [manager() for idx in range(self.nproc)]
        self.conv_handlers = []
        self.threads = []
        self.output_queue = queue.Queue()
        for idx, mg in enumerate(self.managers):
            mg.start()
            m = mg.conv()
            for h in self.chunks[idx]:
                m.add_convolver(self.data[h]['conv'])
            self.conv_handlers.append(m)
            self.threads.append((
                threading.Thread(target=self._send_work, args=(idx, )),
                queue.Queue(), self.output_queue))
        self._running = True
        for th, q1, q2 in self.threads:
            th.daemon = True
            th.start()
        atexit.register(self.__stop__) 
開發者ID:dkriegner,項目名稱:xrayutilities,代碼行數:33,代碼來源:powder.py

示例9: testException

# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import managers [as 別名]
def testException(self):
    manager = multiprocessing.managers.SyncManager()
    manager.start()
    lock = manager.Lock()
    counter = manager.Value('i', 0)
    calls = [(_IncrementCounter, (lock, counter), {}),
             (_RaiseValueError, (), {}),
             (_IncrementCounter, (lock, counter), {})]
    with self.assertRaises(errors.VmUtil.CalledProcessException):
      background_tasks.RunParallelProcesses(calls, max_concurrency=1)
    self.assertEqual(counter.value, 2) 
開發者ID:GoogleCloudPlatform,項目名稱:PerfKitBenchmarker,代碼行數:13,代碼來源:background_tasks_test.py


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