Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic parallel python program freezes on Windows

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?

like image 922
Theodosis Siomos Avatar asked May 27 '18 12:05

Theodosis Siomos


Video Answer


1 Answers

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.

like image 135
Theodosis Siomos Avatar answered Oct 25 '22 01:10

Theodosis Siomos