本文整理汇总了Python中multiprocessing.Manager.put_nowait方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.put_nowait方法的具体用法?Python Manager.put_nowait怎么用?Python Manager.put_nowait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing.Manager
的用法示例。
在下文中一共展示了Manager.put_nowait方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: launch_expeditions
# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import put_nowait [as 别名]
def launch_expeditions( self , task_request_list , moon_name_list=None ):
global expedition
# ---[ 1 ]------------------------------------------------------
self.log.show( 'Checking Moon list sent by user' )
working_moons = []
if not moon_name_list :
self.log.show( 'Traveling to available Moons on Orbit' )
working_moons = self.orbit.values()
else :
self.log.show( 'Traveling to ' + str( moon_name_list ) )
working_moons = [ self.orbit.get_moon( moon_name ) for moon_name in moon_name_list ]
# ---[ 2 ]------------------------------------------------------
self.log.show( 'Build Thread-safe Queues with no maximum size' )
recv_queue = Manager().Queue( )#len(task_request_list) )
send_queue = Manager().Queue( )#len(task_request_list) )
# ---[ 3 ]------------------------------------------------------
self.log.show( 'Enqueue tasks on "send_queue" object' )
for task_obj in task_request_list :
send_queue.put_nowait( str(task_obj) ) # "Normal" Objects are note thread safe!
self.log.show( 'send_queue = ' + str(send_queue.qsize())+'/'+str(len(task_request_list)) + 'tasks')
# ---[ 4 ]------------------------------------------------------
self.log.show( 'Starting up Process Pool' )
pool = Pool(processes=len(working_moons))
for moon in working_moons :
#running_expeditions.append( Process( target=expedition , args=(self.name , moon.name , moon.ip , moon.port , taskrequest_queue , taskresponse_queue, ) ) ) # Process Object
pool.apply_async( func=expedition , args=(self.name , moon.name , moon.ip , moon.port , send_queue , recv_queue , ) )
# ---[ 5 ]------------------------------------------------------
pool.close()
pool.join()
self.log.show( 'recv_queue = '+ str(recv_queue.qsize())+'/'+str(len(task_request_list)) + 'tasks' )
tmp = []
while not recv_queue.empty() :
tmp.append( recv_queue.get() )
self.log.show( 'closing queue' )
self.log.show( 'return results' )
return tmp