]> granicus.if.org Git - python/commitdiff
bpo-31160: test_tempfile: Fix reap_children() warning (#3056)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 10 Aug 2017 11:05:06 +0000 (13:05 +0200)
committerGitHub <noreply@github.com>
Thu, 10 Aug 2017 11:05:06 +0000 (13:05 +0200)
TestRandomNameSequence.test_process_awareness() now calls
os.waitpid() to avoid leaking a zombie process.

Lib/test/test_tempfile.py

index d0cf04b0cb67ca5bac7887cd9cdef0c019c60f20..710756bde64c04fd2758e38c545043e2e2726e8a 100644 (file)
@@ -78,7 +78,6 @@ class BaseTestCase(unittest.TestCase):
     def tearDown(self):
         self._warnings_manager.__exit__(None, None, None)
 
-
     def nameCheck(self, name, dir, pre, suf):
         (ndir, nbase) = os.path.split(name)
         npre  = nbase[:len(pre)]
@@ -184,12 +183,15 @@ class TestRandomNameSequence(BaseTestCase):
         try:
             pid = os.fork()
             if not pid:
+                # child process
                 os.close(read_fd)
                 os.write(write_fd, next(self.r).encode("ascii"))
                 os.close(write_fd)
                 # bypass the normal exit handlers- leave those to
                 # the parent.
                 os._exit(0)
+
+            # parent process
             parent_value = next(self.r)
             child_value = os.read(read_fd, len(parent_value)).decode("ascii")
         finally:
@@ -200,6 +202,10 @@ class TestRandomNameSequence(BaseTestCase):
                     os.kill(pid, signal.SIGKILL)
                 except OSError:
                     pass
+
+                # Read the process exit status to avoid zombie process
+                os.waitpid(pid, 0)
+
             os.close(read_fd)
             os.close(write_fd)
         self.assertNotEqual(child_value, parent_value)