我想使用多处理将工作分散到系统的多个核心上。作为工作的一部分,他们将运行 subprocess.call(..., shell=True)
。当他们这样做时会发生什么?子进程分支是否保留在该核心上?
最佳答案
如果主要工作是在使用 subprocess
模块创建的子进程中完成的,那么您不需要 multiprocessing
将工作分散到多个 CPU 核心上。请参阅Python threading multiple bash subprocesses?
What happens when they do that?
subprocess.call()
运行外部命令并等待其完成。它是否在 multiprocessing
模块创建的工作进程内启动并不重要。
Does the subprocess fork stay on that core?
如果你需要的话;您应该显式设置 CPU 关联性。 psutil
provides a portable way to set/get CPU affinity for a process .
如果您使用numpy
,那么它可能会影响CPU亲和性。请参阅Why does multiprocessing use only a single core after I import numpy?
关于python - Python 的 subprocess 和 multiprocessing 包如何互操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32463721/