我有一个异步函数被这样调用:
from multiprocessing import Process
def my_function(arg1, arg2):
print 'Long process begins'
p = Process(target=my_function, args=(arg1, arg2,)).start()
如何进行此阻止?我需要在运行脚本的其余部分之前完成该过程。
最佳答案
使用p.join()
Block the calling thread until the process whose join() method is called terminates or until the optional timeout occurs.
If timeout is None then there is no timeout.
A process can be joined many times.
A process cannot join itself because this would cause a deadlock. It is an error to attempt to join a process before it has been started.
关于python - Python 中的阻塞子进程函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10896202/