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

标签 python multiprocessing blocking

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

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/

相关文章:

concurrency - 如何在非阻塞系统中处理货币交易?

python - 如何为蜘蛛设置管道

从这个文本文件中提取值的 Pythonic 方法

python - 传递给函数的对象是否作为参数,得到重复

python - 多处理比 Windows 中的串行处理慢(但在 Linux 中不是)

python twisted INotify 不阻塞 react 器

python - 软件包安装在 anaconda\lib\site-packages 中并在 spy 程序中找到,但不在 jupyter 笔记本中

python - 检查 python 是否删除文件夹成功,如果成功,则继续

Python 多处理,在循环中多次使用池在第一次迭代后卡住

cocoa - 如何检查 NSFileHandle 是否有可用数据?