【发布时间】:2014-06-15 15:37:14
【问题描述】:
当通过 Python 的subprocess 模块调用需要较长时间的 linux 二进制文件时,是否会释放 GIL?
我想并行化一些从命令行调用二进制程序的代码。使用线程(通过threading 和multiprocessing.pool.ThreadPool)还是multiprocessing 更好?我的假设是,如果 subprocess 发布 GIL,那么选择 threading 选项会更好。
【问题讨论】:
-
请澄清。当前的答案认为您担心子进程本身以某种方式持有 GIL,但我认为您可能担心
subprocess.call()或subprocess.Popen(...).wait()会阻塞调用者中的其他线程。 (他们没有。) -
@pilcrow:作为从 Google 遇到这个问题的人,我建议您将您的评论变成答案,因为与现有答案不同,它解决了实际问题。
-
@Rörd:我现在已经这样做了,谢谢。
标签: python multithreading subprocess python-multithreading gil