我有一点多处理代码,如下所示。当我开始这项工作时,一切都很好,我看到我的队列大小迅速减少。再慢一点。那么它根本就没有取得任何进展。但我仍然可以看到12个python进程在运行。你知道吗
我怀疑有一些错误,大毛例程正在命中,进程正在慢慢消失。但是我怎样才能窥视async\u结果结构来查看底层池进程的状态呢?你知道吗
(也有可能是我用错了成语。)
import traceback
import multiprocessing
from Queue import Empty
def do_something(q):
item = q.get_nowait()
while item:
try:
big_hairy_routine(item)
except Exception, e:
traceback.print_exc()
sys.exit(1)
try:
item = q.get_nowait()
except Empty:
item = None
manager = multiprocessing.Manager()
q = manager.Queue()
pool = multiprocessing.Pool(processes=10)
for item in (1,2,3,4,5):
q.put(item)
async_result = pool.apply_asnc(do_something, (q,))
while q.qsize > 0:
print "there are %s items in queue" % q.qsize()
if async_result.ready():
print "we're done!"
break
time.sleep(30)
目前没有回答
相关问题 更多 >
编程相关推荐