[Python-checkins] bpo-31160: test_tempfile: Fix reap_children() warning (#3056)
Victor Stinner
webhook-mailer at python.org
Thu Aug 10 07:05:09 EDT 2017
https://github.com/python/cpython/commit/6c8c2943d996b59a48d331f61f22cbe72933910e
commit: 6c8c2943d996b59a48d331f61f22cbe72933910e
branch: master
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-08-10T13:05:06+02:00
summary:
bpo-31160: test_tempfile: Fix reap_children() warning (#3056)
TestRandomNameSequence.test_process_awareness() now calls
os.waitpid() to avoid leaking a zombie process.
files:
M Lib/test/test_tempfile.py
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index d0cf04b0cb6..710756bde64 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -78,7 +78,6 @@ def setUp(self):
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 @@ def test_process_awareness(self):
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 @@ def test_process_awareness(self):
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)
More information about the Python-checkins
mailing list