0

So this is a code snippet from python doc to demonstrate multiprocessing module. I opened a empty file 'multi_process_test.py' and typed in these code.

from multiprocessing import Process
import sys

def f(name):
    print('hello', name)

if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()

And the weird part is if I run it under Spyder, the program prints nothing, but if I run the source code in powershell env by 'python multi_process_test.py', the console will prints 'hello bob' as expected, can s.b. help to explain why this happen? Or any hint to resolve this difference.

Appreciated for your help.

1313e
  • 1,112
  • 9
  • 17
leo lee
  • 33
  • 4
  • Reason for that is because Spyder will automatically open an IPython console on a single core. Because of that, multithreading is not possible in Spyder. – 1313e Jan 10 '18 at 06:23
  • hmm..so the multiprocessing module won't be able execute if there is only one core? Or just constrained by the Spyder setup. @1313e – leo lee Jan 10 '18 at 06:28
  • Multiprocessing requires that you can spawn multiple processes. You need access to multiple threads in order to do so. In an IPython console, you only have access to those that the console has access to, which are the ones it is running on. – 1313e Jan 10 '18 at 06:38
  • @1313e, please stop spreading false rumors about Spyder. It's completely false what you said. – Carlos Cordoba Jan 11 '18 at 17:36
  • @leolee, please read [this answer](https://stackoverflow.com/q/29629103/438386) to understand how to fix your problem. – Carlos Cordoba Jan 11 '18 at 17:40
  • @leolee, by the way, `multiprocessing` is not the best way to parallelize your code on Windows. You should consider other options like `ipyparallel` or `joblib`. – Carlos Cordoba Jan 11 '18 at 17:40
  • @CarlosCordoba Oh...thank you for your answer, and thank you for your contributions to Spyder, haha. – leo lee Jan 23 '18 at 10:07

0 Answers0