Browse Source
bpo-35727: Use exit code 0 on sys.exit() in multiprocessing.Process. (GH-11538)
pull/18592/head
Christopher Hunt
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
22 additions and
11 deletions
-
Lib/multiprocessing/process.py
-
Lib/test/_test_multiprocessing.py
-
Misc/ACKS
-
Misc/NEWS.d/next/Library/2019-01-12-20-39-34.bpo-35727.FWrbHn.rst
|
|
|
@ -317,12 +317,12 @@ class BaseProcess(object): |
|
|
|
finally: |
|
|
|
util._exit_function() |
|
|
|
except SystemExit as e: |
|
|
|
if not e.args: |
|
|
|
exitcode = 1 |
|
|
|
elif isinstance(e.args[0], int): |
|
|
|
exitcode = e.args[0] |
|
|
|
if e.code is None: |
|
|
|
exitcode = 0 |
|
|
|
elif isinstance(e.code, int): |
|
|
|
exitcode = e.code |
|
|
|
else: |
|
|
|
sys.stderr.write(str(e.args[0]) + '\n') |
|
|
|
sys.stderr.write(str(e.code) + '\n') |
|
|
|
exitcode = 1 |
|
|
|
except: |
|
|
|
exitcode = 1 |
|
|
|
|
|
|
|
@ -864,12 +864,21 @@ class _TestSubclassingProcess(BaseTestCase): |
|
|
|
|
|
|
|
os.unlink(testfn) |
|
|
|
|
|
|
|
for reason in (True, False, 8): |
|
|
|
p = self.Process(target=sys.exit, args=(reason,)) |
|
|
|
p.daemon = True |
|
|
|
p.start() |
|
|
|
join_process(p) |
|
|
|
self.assertEqual(p.exitcode, reason) |
|
|
|
cases = [ |
|
|
|
((True,), 1), |
|
|
|
((False,), 0), |
|
|
|
((8,), 8), |
|
|
|
((None,), 0), |
|
|
|
((), 0), |
|
|
|
] |
|
|
|
|
|
|
|
for args, expected in cases: |
|
|
|
with self.subTest(args=args): |
|
|
|
p = self.Process(target=sys.exit, args=args) |
|
|
|
p.daemon = True |
|
|
|
p.start() |
|
|
|
join_process(p) |
|
|
|
self.assertEqual(p.exitcode, expected) |
|
|
|
|
|
|
|
# |
|
|
|
# |
|
|
|
|
|
|
|
@ -746,6 +746,7 @@ Lawrence Hudson |
|
|
|
Michael Hudson |
|
|
|
Jim Hugunin |
|
|
|
Greg Humphreys |
|
|
|
Chris Hunt |
|
|
|
Eric Huss |
|
|
|
Nehal Hussain |
|
|
|
Taihyun Hwang |
|
|
|
|
|
|
|
@ -0,0 +1 @@ |
|
|
|
Fix sys.exit() and sys.exit(None) exit code propagation when used in multiprocessing.Process. |