]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35727: Use exit code 0 on sys.exit() in multiprocessing.Process. (GH-11538)
authorChristopher Hunt <chrahunt@gmail.com>
Fri, 21 Feb 2020 09:33:04 +0000 (17:33 +0800)
committerGitHub <noreply@github.com>
Fri, 21 Feb 2020 09:33:04 +0000 (10:33 +0100)
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 [new file with mode: 0644]

index be13c079bb89b3a0a435bc8184914638776d8de7..0b2e0b45b2397be0a672b36b7e4c572b3996cf53 100644 (file)
@@ -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
index 4e48cd45e14ca745412165e3dd167859d174e2c0..73dc75d34a6f012db5c2149b1788a2e44afb34cd 100644 (file)
@@ -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)
 
 #
 #
index 976c26eb9117be79f8aeddf8c67e2408df6bbac9..f329a2d4a7d33fbcb2266ef961e788de4a218d9f 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -746,6 +746,7 @@ Lawrence Hudson
 Michael Hudson
 Jim Hugunin
 Greg Humphreys
+Chris Hunt
 Eric Huss
 Nehal Hussain
 Taihyun Hwang
diff --git a/Misc/NEWS.d/next/Library/2019-01-12-20-39-34.bpo-35727.FWrbHn.rst b/Misc/NEWS.d/next/Library/2019-01-12-20-39-34.bpo-35727.FWrbHn.rst
new file mode 100644 (file)
index 0000000..9f3fa40
--- /dev/null
@@ -0,0 +1 @@
+Fix sys.exit() and sys.exit(None) exit code propagation when used in multiprocessing.Process.
\ No newline at end of file