diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-31 22:27:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 22:27:18 (GMT) |
commit | 16d75675d2ad2454f6dfbf333c94e6237df36018 (patch) | |
tree | f0113562218572a8632ada148ff58d17aba8b68e | |
parent | 40bfdb1594189f3c0238e5d2098dc3abf114e200 (diff) | |
download | cpython-16d75675d2ad2454f6dfbf333c94e6237df36018.zip cpython-16d75675d2ad2454f6dfbf333c94e6237df36018.tar.gz cpython-16d75675d2ad2454f6dfbf333c94e6237df36018.tar.bz2 |
bpo-31160: Fix race condition in test_os.PtyTests (GH-19263)
bpo-31160, bpo-40094: Wait until the process completes before closing
the PTY to prevent sending SIGHUP to the child process.
-rw-r--r-- | Lib/test/test_builtin.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 86e5f1d..eaada1b 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1846,6 +1846,7 @@ class PtyTests(unittest.TestCase): os.close(w) self.skipTest("pty.fork() raised {}".format(e)) raise + if pid == 0: # Child try: @@ -1859,9 +1860,11 @@ class PtyTests(unittest.TestCase): finally: # We don't want to return to unittest... os._exit(0) + # Parent os.close(w) os.write(fd, terminal_input) + # Get results from the pipe with open(r, "r") as rpipe: lines = [] @@ -1871,6 +1874,7 @@ class PtyTests(unittest.TestCase): # The other end was closed => the child exited break lines.append(line) + # Check the result was got and corresponds to the user's terminal input if len(lines) != 2: # Something went wrong, try to get at stderr @@ -1888,11 +1892,14 @@ class PtyTests(unittest.TestCase): child_output = child_output.decode("ascii", "ignore") self.fail("got %d lines in pipe but expected 2, child output was:\n%s" % (len(lines), child_output)) - os.close(fd) - # Wait until the child process completes + # Wait until the child process completes before closing the PTY to + # prevent sending SIGHUP to the child process. support.wait_process(pid, exitcode=0) + # Close the PTY + os.close(fd) + return lines def check_input_tty(self, prompt, terminal_input, stdio_encoding=None): |