I have the following code in ipython where the child process tries to do sys.exit(...)
but causes the parent process to hang. Is this a bug? Any idea how to workaround this?
In [1]: from 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() <---- it is hanging here forever.
I have also tried to put raise SystemExit(...)
instead of sys.exit(...)
but it was the same thing. The only workaround I know is to put raise Exception(...)
which turned out to work just fine.
I understand that sys.exit
is essentially the same as raise SystemExit
, but this exception should be delegated up to its parent process and thus r.get()
should be able to receive this exception correct? But it seems to be getting stuck on recv
call. Is this a bug in multiprocessing
module?