【发布时间】:2019-05-01 09:48:57
【问题描述】:
假设我们有一个multiprocessing.Pool,其中工作线程共享一个multiprocessing.JoinableQueue,使工作项出队并可能使更多工作入队:
def worker_main(queue):
while True:
work = queue.get()
for new_work in process(work):
queue.put(new_work)
queue.task_done()
当队列填满时,queue.put() 将阻塞。只要至少有一个进程从队列中读取queue.get(),它就会释放队列中的空间以解除对写入者的阻塞。但所有进程都可能同时在 queue.put() 处阻塞。
有没有办法避免像这样被卡住?
【问题讨论】:
标签: python python-multiprocessing