7

This is the basic Python example from https://docs.python.org/2/library/multiprocessing.html#module-multiprocessing.pool on parallel processing

from multiprocessing import Pool

def f(x):
    return x*x

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

which I can't run for some reason on my PC. When I try to execute the third block the program freezes. My OS is Windows 10. I run the program on the Spyder IDE and I have an anaconda installation. What is possibly the problem?

Theodosis Siomos
  • 314
  • 1
  • 16
  • Most likely due to the environment(s). Try running it from the command line and see what happens. – martineau May 27 '18 at 13:19
  • Does this answer your question? [python multiprocess don't finish properly](https://stackoverflow.com/questions/13395636/python-multiprocess-dont-finish-properly) – P_Sta May 11 '21 at 20:39

1 Answers1

3

This is a problem Windows users have and it is not relevant to the anaconda environment. I found the solution. Firstly you have to create another .py file in order to save the f(x) function. Then you import the function you have created and the program runs smoothly.

Theodosis Siomos
  • 314
  • 1
  • 16
  • 1
    That's weird. The script in the question works fine in Windows. It has the proper `__name__ == '__main__'` test. I think this is either a bug or a misconfiguration in your IDE. – Eryk Sun May 27 '18 at 20:35