Sunday, 15 February 2015

Python 2.7.3 Multiprocessing Pool hanging -



Python 2.7.3 Multiprocessing Pool hanging -

i have next code in ipython kid process tries sys.exit(...) causes parent process hang. bug? thought how workaround this?

in [1]: multiprocessing import pool in [2]: def f(): ...: import sys ...: sys.exit('exiting system...') ...: in [3]: p = pool(processes=2) in [4]: r = p.apply_async(f, []) in [5]: r.get() <---- hanging here forever.

i have tried set raise systemexit(...) instead of sys.exit(...) same thing. workaround know set raise exception(...) turned out work fine.

i understand sys.exit same raise systemexit, exception should delegated parent process , r.get() should able receive exception correct? seems getting stuck on recv call. bug in multiprocessing module?

you're causing pool worker process exit when phone call sys.exit(). systemexit exception special-cased; when raise it, process raised in exits. exception doesn't propagated caller. so, means in example, worker process never returns parent. , parent process wait around forever kid homecoming that's never going returned. see this question more in-depth give-and-take of behavior.

i argue bug, , when sub-process exits, pool should marked broken, , outstanding tasks should aborted. how concurrent.futures.processpoolexecutor behaves already. i've submitted patch adds behavior multiprocessing.pool, far hasn't been reviewed.

now, original question. looks want parent process exit here, not child. that, you'll need homecoming object parent, , have parent exit when receives object. looks you've discovered can raising exception.

python multiprocessing

No comments:

Post a Comment