本文整理汇总了Python中multiprocessing.Queue.join方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.join方法的具体用法?Python Queue.join怎么用?Python Queue.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Queue
的用法示例。
在下文中一共展示了Queue.join方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import join [as 别名]
def execute(self, item_generator, item_processor):
# Create a queue to communicate with the worker threads
try:
queue = Queue()
threads = []
# Create 8 worker threads
for x in range(self.no_of_threads):
worker = Neo4jUploadWorker(queue, item_processor)
# Setting daemon to True will let the main thread exit even though the workers are blocking
worker.daemon = True
worker.start()
threads.append(worker)
# Put the tasks into the queue as a tuple
for item in item_generator.generate:
queue.put(item)
# Causes the main thread to wait for the queue to finish processing all the tasks
queue.join()
# stop workers
for i in range(self.no_of_threads):
queue.put(None)
for t in threads:
t.join()
finally:
print("In the finally")
item_generator.close()
for i in range(self.no_of_threads):
queue.put(None)
for t in threads:
t.join()
示例2: main
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import join [as 别名]
def main():
manager = Manager()
d = manager.dict()
que=Queue(10000)
p = Process(recv_items(que))
p.daemon = True
p.start()
pool = Pool(100)
for i in range(1,100):
pool.apply_async(handle,args=(que,i,d))
p.join()
que.join()
示例3: netService
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import join [as 别名]
def netService(a, cmd):
while True:
data = listen()
print(data[1].decode("utf-8")[0])
if data[1].decode("utf-8")[0] == 'd':
dry = ['Not dry', 'Dry', 'Too dry']
send('{"Temperature":%d,"Humidity":%d,"Dry Status":"%s","Light":%d}' % (a[0], a[1], dry[a[2]], a[3]), data)
else:
send("a", data)
def add(l, cmd):
for i in range(4):
l.append(i)
if __name__ == "__main__":
q = Queue()
m = Manager()
cmd='1'
l = m.list()
p = Process(target=netService, args=(l, cmd))
q = Process(target=add, args=(l, cmd))
p.start()
q.start()
p.join()
q.join()
示例4: DeployManager
# 需要导入模块: from multiprocessing import Queue [as 别名]
# 或者: from multiprocessing.Queue import join [as 别名]
#.........这里部分代码省略.........
# Step: Check Delete Service
self._delete_unused(dry_run=True)
# Step: Check Service
self._check_deploy()
self._set_deploy_list()
def delete(self):
self.environment = self._args.environment
self.force = self._args.force
self._start_threads()
self._fetch_ecs_information(is_all=True)
if self.delete_service_list == 0 and self.delete_scheduled_task_list == 0:
info("No delete service or scheduled task")
return
h1("Delete Service or Scheduled Task")
for service in self.delete_service_list:
print("* %s" % service.service_name)
for task in self.delete_scheduled_task_list:
print("* %s" % task.family)
if not self.force:
reply = input("\nWould you like delete all ecs service in %s (y/n)\n" % self.environment)
if reply != 'y':
return
self._delete_unused()
def _stop_scheduled_task(self):
if len(self.deploy_scheduled_task_list) > 0:
h1("Step: Stop ECS Scheduled Task")
for task in self.deploy_scheduled_task_list:
self.task_queue.put([task, ProcessMode.stopScheduledTask])
self.task_queue.join()
def _stop_before_deploy(self):
if len(self._unstopped_primary_stop_before_deploy_service_list()) > 0 \
or len(self._unstopped_stop_before_deploy_service_list()) > 0:
h1("Step: Stop ECS Service Before Deploy")
for service in self._unstopped_primary_stop_before_deploy_service_list():
self.task_queue.put([service, ProcessMode.stopBeforeDeploy])
for service in self._unstopped_stop_before_deploy_service_list():
self.task_queue.put([service, ProcessMode.stopBeforeDeploy])
self.task_queue.join()
h2("Wait for Service Status 'Stable'")
self._wait_for_stable(self._unstopped_primary_stop_before_deploy_service_list())
self._wait_for_stable(self._unstopped_stop_before_deploy_service_list())
def _start_after_deploy(self):
if len(self.primary_stop_before_deploy_service_list) > 0:
h1("Step: Start Primary ECS Service After Deploy")
for service in self.primary_stop_before_deploy_service_list:
self.task_queue.put([service, ProcessMode.deployService])
self.task_queue.join()
h2("Wait for Service Status 'Stable'")
self._wait_for_stable(self.primary_stop_before_deploy_service_list)
if len(self.stop_before_deploy_service_list) > 0:
h1("Step: Start ECS Service After Deploy")
for service in self.stop_before_deploy_service_list:
self.task_queue.put([service, ProcessMode.deployService])
self.task_queue.join()
h2("Wait for Service Status 'Stable'")
self._wait_for_stable(self.stop_before_deploy_service_list)
def _deploy_scheduled_task(self):
if len(self.deploy_scheduled_task_list) > 0: