0

(this is using Python 2.7)

I have found similar links but not about the exact same issue than what I am having. This program hangs on the map_async, and never finishes, I can see the Python process getting created but it never completes:

import multiprocessing


def main():
    PROCESSES = 4
    print 'Creating pool with %d processes\n' % PROCESSES
    pool = multiprocessing.Pool(PROCESSES)
    r = pool.map_async(pow3, range(10))
    r.wait()


def pow3(x):
    try:
        return x**3
    except:
        print('%s: %s' % (x, traceback.format_exc()))

if __name__ == '__main__':
    main()

1 Answer 1

2

It works fine.
Are you running this in an interactive interpreter?
See this note from the docs:

Note Functionality within this package requires that the main module be importable by the children. This is covered in Programming guidelines however it is worth pointing out here. This means that some examples, such as the multiprocessing.Pool examples will not work in the interactive interpreter. For example:

>>> from multiprocessing import Pool   
>>> p = Pool(5)   

>>> def f(x):   
...     return x*x  

>>> p.map(f, [1,2,3])  

Process PoolWorker-1:
Process PoolWorker-2:
Process PoolWorker-3:

Traceback (most recent call last):

AttributeError: 'module' object has no attribute 'f'
AttributeError: 'module' object has no attribute 'f'
AttributeError: 'module' object has no attribute 'f'

(If you try this it will actually output three full tracebacks interleaved in a semi-random fashion, and then you may have to stop the master process somehow.)

Sign up to request clarification or add additional context in comments.

1 Comment

I am trying this in pyScripter, it was working fine until Friday. You seem to be right, it works when I just run the program by double clicking it (running through python.exe)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.