This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: multiprocessing: sys.exit() from a child with a non-int exit code exits with 0
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brodie, jnoller, sbt
Priority: normal Keywords: patch

Created on 2013-10-21 19:58 by brodie, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
multiprocessing-sys-exit-3.3.patch brodie, 2013-10-21 20:04
multiprocessing-sys-exit-2.7.patch brodie, 2013-10-21 20:04
Messages (3)
msg200833 - (view) Author: Brodie Rao (brodie) Date: 2013-10-21 19:58

  $ python
  >>> import sys
  >>> sys.exit('foo')
  $ echo $?

However, with multiprocessing:

  >>> import sys
  >>> from multiprocessing import Process
  >>> p = Process(target=lambda: sys.exit('foo'))
  >>> p.start()
  >>> foo
  >>> p.join()
  >>> p.is_alive()
  >>> p.exitcode

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.
msg200836 - (view) Author: Brodie Rao (brodie) Date: 2013-10-21 20:04
Here's the patch for 3.3.
msg203203 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-11-17 17:39
Thanks for the patches.

Fixed in 7aabbe919f55, 11cafbe6519f.
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63537
2013-11-17 17:39:38sbtsetstatus: open -> closed
resolution: fixed
messages: + msg203203

stage: resolved
2013-10-21 20:06:22brodiesetnosy: + jnoller, sbt
2013-10-21 20:04:23brodiesetfiles: + multiprocessing-sys-exit-2.7.patch
2013-10-21 20:04:01brodiesetfiles: + multiprocessing-sys-exit-3.3.patch
keywords: + patch
messages: + msg200836
2013-10-21 19:58:25brodiecreate