gpt4 book ai didi

python - Python 中的阻塞子进程函数?

转载 作者:行者123 更新时间:2023-12-01 06:00:02 26 4
gpt4 key购买 nike

我有一个异步函数被这样调用:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com