0

I have two python scripts, script A and script B. My environment is Linux with the CPython implementation.

At some point in script A use Process from multiprocessing to start multiple processes using the normal p.start() and p.join() procedure.

Script B calls script A in the following way:

subprocess.call(["python", "script_A.py"])

When I run script A by itself, it uses all the cores that I ask it to use.

When I run script A from script B, only one core is used, no matter what. How can I call script A from script B and have it use all the cores that I ask it to use?

doniyor
  • 36,596
  • 57
  • 175
  • 260
Jadiel de Armas
  • 8,405
  • 7
  • 46
  • 62
  • Do you mean you're using the `multiprocessing` library? What platform is this on? Can you share the `subprocess` call you're making? And are you by any chance using `numpy` in script B? – dano Aug 04 '14 at 03:24
  • http://stackoverflow.com/questions/2935836/can-a-python-script-know-that-another-instance-of-the-same-script-is-running – Avinash Babu Aug 04 '14 at 03:25
  • @AvinashBabu Not sure what that has to do with this question. – dano Aug 04 '14 at 03:28
  • am like confused ..i didnt get the question properly so i gave a link to the question which is similar – Avinash Babu Aug 04 '14 at 03:29
  • 1
    @ASDF I would expect script A to use all cores no matter what. There's only one explanation I can think of: If script B is using `numpy`, the processor affinity may be getting changed in script B in a way that will prevent `multiprocessing` from using more than one core (see [this answer](http://stackoverflow.com/a/15647474/2073595) for more info). If that's the case, I think the processor affinity of script B will be inherited by script A, which will cause the behavior you're seeing. If you're not using `numpy`, I have no idea what's causing the issue. – dano Aug 04 '14 at 05:05
  • I've edited your question to remove references to multithreading, because that's not what's going on here. Also, do your calls to `p.start()` explicitly specify a number of processes, or do you leave it up to the default argument? – Patrick Collins Aug 04 '14 at 07:07
  • @Patrick: Thanks for the edits. @dano: That was exactly what was going on with `numpy`. Thanks a lot. – Jadiel de Armas Aug 04 '14 at 17:34

0 Answers0