【发布时间】:2015-10-25 23:20:21
【问题描述】:
我已经并行运行了两个Process 实例:
from multiprocessing import Process
def foobar():
return x*x
def barfoo():
return x+x
thread_fb = Process(target = foobar, args=(3,)))
thread_bf = Process(target = barfoo, args=(3,)))
thread_fb.start(); thread_bf.start()
thread_fb.wait(); thread_bf.wait()
它抛出了这个错误:
AttributeError: 'Process' object has no attribute 'wait'
如何等待所有multiprocessing.Process结束?
使用threading其他多处理/线程库时的等价物是什么?
【问题讨论】:
-
这是
join(),而不是wait()。这适用于multiprocessing.Process和threading.Thread。此外,粘贴的代码将失败,因为您试图将参数传递给您的两个函数,但没有一个函数接受参数。看起来你想要def foobar(x):和def barfoo(x):。
标签: python multithreading subprocess python-multiprocessing