简体   繁体   中英

python multiprocessing pool.map hangs

I cannot make even the simplest of examples of parallel processing using the multiprocessing package run in python 2.7 (using spyder as a UI on windows) and I need help figuring out the issue. I have run conda update so all of the packages should be up to date and compatible.

Even the first example in the multiprocessing package documentation (given below) wont work, it generates 4 new processes but the console just hangs. I have tried everything I can find over the last 3 days but none of the code that runs without hanging will allocate more than 25% of my computing power to this task (I have a 4 core computer).

I have given up on running the procedure I have designed and need parallel processing for at this point and I am only trying to get proof of concept so I can build from there. Can someone explain and point me in the right direction? Thanks

Example 1 from https://docs.python.org/2/library/multiprocessing.html

#

from multiprocessing import Pool

def f(x):
    return x*x

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

Example 2 (modified from original) from http://chriskiehl.com/article/parallelism-in-one-line/

from multiprocessing import Pool

def fn(i):
    return [i,i*i,i*i*i]

test = range(10)

if __name__ == '__main__':    
    pool = Pool() 
    results = map(fn,test)
    pool.close() 
    pool.join() 

I apologize if there is indeed an answer to this as it seems as though I should be able to manage such a modest task but I am not a programmer and the resources I have found have been less than helpful given my very limited level of knowledge. Please let me know what further information is needed.

Thank you.

After installing spyder on my virtualmachine, it seems to be a spyder specific bug. Example 1 works in IDLE, executed via the command line, executed from within spyder (first saved and then executed), but not when executed line by line in spyder.

I would suggest simply to create a new file in spyder, add the lines of code, save it, and then run it..


For related reports see:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM