Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is this multiprocessing.Pool stuck?

CODE:

from multiprocessing import Pool
print ('parent')
max_processes = 4
def foo(result):
    print (result)
def main():
    pool = Pool(processes=max_processes)
    while True:
        pool.apply_async(foo, 5)
if __name__ == '__main__':
    main()

‘parent’ gets printed 5 times, so initial pools were created. But there was no execution from print(result) statement.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are passing the arguments incorrectly in your call to apply_async. The arguments need to be in a tuple (or other sequence, maybe), but you’re passing 5 as a bare number.

Try:

def main():
    pool = Pool(processes=max_processes)
    while True:
        pool.apply_async(foo, (5,)) # make a 1-tuple for the args!
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading