本文整理汇总了Python中multiprocessing.managers.BaseManager.get_dispatch_queue方法的典型用法代码示例。如果您正苦于以下问题:Python BaseManager.get_dispatch_queue方法的具体用法?Python BaseManager.get_dispatch_queue怎么用?Python BaseManager.get_dispatch_queue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.managers.BaseManager
的用法示例。
在下文中一共展示了BaseManager.get_dispatch_queue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: from multiprocessing.managers import BaseManager [as 别名]
# 或者: from multiprocessing.managers.BaseManager import get_dispatch_queue [as 别名]
def start(self):
BaseManager.register('get_dispatch_queue',
callable=self.get_dispatch_queue)
BaseManager.register('get_finished_queue',
callable=self.get_finished_queue)
manager = BaseManager(address=('0.0.0.0', 8000),
authkey=b'dispatcher')
manager.start()
dispatch_queue = manager.get_dispatch_queue()
finished_queue = manager.get_finished_queue()
job_id = 0
unfinished = self.rnd * self.batch
for rnd in range(self.rnd):
for i in range(self.batch):
job = Job(job_id=job_id)
job_id += 1
print('Dispatch Job {}'.format(job))
dispatch_queue.put(job)
while not dispatch_queue.empty():
finished_job = finished_queue.get(60)
unfinished -= 1
print('Job finished {}'.format(finished_job))
dispatch_queue.put(None)
while unfinished > 0:
finished_job = finished_queue.get(60)
unfinished -= 1
print('Job finished {}'.format(finished_job))
manager.shutdown()