0

Python2.7 Windows10 spyder3.3.0

I tried a tutorial code using multiprocessing Pool, but it does not seem to start. Does anyone have any ideas? My Python console just stops and never works again without terminating the console. The code is as below. I really appreciate your asking me if you would need to know more about my Python version or any PC specs.

from multiprocessing import Pool

def f(x):
    return x*x

if __name__ == '__main__':
    p = Pool(5)
    print(p.map(f, [1, 2, 3]))

The output should be as below.

[1, 4, 9]

P.S. Thank all of you guys giving me the comment! I understand that it is not working in Spyder. But, how about in PyCharm? If any of you have tried it in PyCharm, Could you tell me if it is working?

Thank you all guys!

U.T
  • 25
  • 3
  • 2
    AFAIK Spyder has issues with multiprocessing in general. I suggest you switch your IDE. – Darkonaut Apr 19 '19 at 11:27
  • This works as expected when I run that script from command line with `python2.7`. I guess it's a problem of your IDE. – Right leg Apr 19 '19 at 11:32
  • @Darkonaut is probably right. Check this issue [here](https://stackoverflow.com/questions/48078722/no-multiprocessing-print-outputs-spyder) – TheDarkKnight Apr 19 '19 at 11:33
  • @Darkonaut, Right leg and theDarkKnight, thank you all of you guys! I did not expect that I could get reply such promptly and you guys' answer were really helpful! – U.T Apr 19 '19 at 11:55
  • Don't run multiprocessing in the IPython console from Spyder, it doesn't work. – Mathieu Apr 19 '19 at 13:08

1 Answers1

0

Some suggestions to try:

  • Start python from the terminal
  • Copy and paste your code
  • Execute

There is nothing wrong with your code. I ran it using python 2.7.15 as well as 3.6.2, as well as in the pycharm console.

Tammo Heeren
  • 1,966
  • 3
  • 15
  • 20