]> granicus.if.org Git - python/commitdiff
bpo-31160: Fix test_random for zombie process (#3045)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 9 Aug 2017 15:59:05 +0000 (17:59 +0200)
committerGitHub <noreply@github.com>
Wed, 9 Aug 2017 15:59:05 +0000 (17:59 +0200)
TestModule.test_after_fork() now calls os.waitpid() to read the exit
status of the child process to avoid creating a zombie process.

Lib/test/test_random.py

index f657b46b3a87587dd36fd3579df56a596466c4ff..fbb1cf6696e5314d48f5b2332ef6a41dbe57b848 100644 (file)
@@ -907,7 +907,9 @@ class TestModule(unittest.TestCase):
     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 @@ class TestModule(unittest.TestCase):
             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()