1

I want to use multiprocessing to spread work across a system's multiple cores. As part of the work, they will run subprocess.call(..., shell=True). What happens when they do that? Does the subprocess fork stay on that core?

user592419
  • 5,103
  • 9
  • 42
  • 67

1 Answers1

2

If the main work is done in the child processes created using subprocess module then you don't need multiprocessing to spread the work across multiple CPU cores. See Python threading multiple bash subprocesses?

What happens when they do that?

subprocess.call() runs an external command and waits for it to complete. It doesn't matter whether it is started inside a worker process created by multiprocessing module or not.

Does the subprocess fork stay on that core?

If you need it; you should set CPU affinity explicitly. psutil provides a portable way to set/get CPU affinity for a process.

If you use numpy then it may affect the cpu affinity. See Why does multiprocessing use only a single core after I import numpy?

Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670