当前位置: 首页>>代码示例>>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;未经允许,请勿转载。