diff options
author | Christopher Hunt <chrahunt@gmail.com> | 2020-02-21 09:33:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-21 09:33:04 (GMT) |
commit | c2ac4cf040ea950bf552d1e77bea613a1a5474fe (patch) | |
tree | 00d33e24b2e69458a109f64e66bd1b619bb219f5 /Lib | |
parent | baf29b221682be0f4fde53a05ea3f57c3c79f431 (diff) | |
download | cpython-c2ac4cf040ea950bf552d1e77bea613a1a5474fe.zip cpython-c2ac4cf040ea950bf552d1e77bea613a1a5474fe.tar.gz cpython-c2ac4cf040ea950bf552d1e77bea613a1a5474fe.tar.bz2 |
bpo-35727: Use exit code 0 on sys.exit() in multiprocessing.Process. (GH-11538)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/multiprocessing/process.py | 10 | ||||
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 21 |
2 files changed, 20 insertions, 11 deletions
diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py index be13c07..0b2e0b4 100644 --- a/Lib/multiprocessing/process.py +++ b/Lib/multiprocessing/process.py @@ -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 diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 4e48cd4..73dc75d 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -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) # # |