[Python-checkins] bpo-31160: Fix test_random for zombie process (#3045)

Victor Stinner webhook-mailer at python.org
Wed Aug 9 11:59:11 EDT 2017


https://github.com/python/cpython/commit/da5e9301877346942fa4279612750d6a09e05153
commit: da5e9301877346942fa4279612750d6a09e05153
branch: master
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-08-09T17:59:05+02:00
summary:

bpo-31160: Fix test_random for zombie process (#3045)

TestModule.test_after_fork() now calls os.waitpid() to read the exit
status of the child process to avoid creating a zombie process.

files:
M Lib/test/test_random.py

diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index f657b46b3a8..fbb1cf6696e 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -907,7 +907,9 @@ def __init__(self, newarg=None):
     def test_after_fork(self):
         # Test the global Random instance gets reseeded in child
         r, w = os.pipe()
-        if os.fork() == 0:
+        pid = os.fork()
+        if pid == 0:
+            # child process
             try:
                 val = random.getrandbits(128)
                 with open(w, "w") as f:
@@ -915,12 +917,16 @@ def test_after_fork(self):
             finally:
                 os._exit(0)
         else:
+            # parent process
             os.close(w)
             val = random.getrandbits(128)
             with open(r, "r") as f:
                 child_val = eval(f.read())
             self.assertNotEqual(val, child_val)
 
+            pid, status = os.waitpid(pid, 0)
+            self.assertEqual(status, 0)
+
 
 if __name__ == "__main__":
     unittest.main()



More information about the Python-checkins mailing list