Issue 19338: multiprocessing: sys.exit() from a child with a non-int exit code exits with 0 (original) (raw)
Normally:
$ python
import sys sys.exit('foo') foo $ echo $? 1
However, with multiprocessing:
import sys from multiprocessing import Process p = Process(target=lambda: sys.exit('foo')) p.start() foo
p.join() p.is_alive() False p.exitcode 0
p.exitcode should be 1, not 0. sys.exit() with a non-int object should always exit with 1.
This regression was introduced in da5b370f41a1 on the 2.7 branch (making it into the 2.7.4 release) and 4346cba353b4 on the 3.2 branch (making it into the 3.2.5 release).
Less important things to note:
multiprocessing calls str() on the object passed to sys.exit() to print it out. The interpreter doesn't do that with the argument is a unicode object (it tries to let sys.stderr encode it and print it).
The interpreter also ignores all exceptions in this process.
I'll attach patches for the 2.7 and 3.3 branches that just addresses the exit code problem.