8000 bpo-31160: Fix race condition in test_os.PtyTests (GH-19263) · python/cpython@16d7567 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16d7567

Browse files
authored
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.
1 parent 40bfdb1 commit 16d7567

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Lib/test/test_builtin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,7 @@ def run_child(self, child, terminal_input):
18461846
os.close(w)
18471847
self.skipTest("pty.fork() raised {}".format(e))
18481848
raise
1849+
18491850
if pid == 0:
18501851
# Child
18511852
try:
@@ -1859,9 +1860,11 @@ def run_child(self, child, terminal_input):
18591860
finally:
18601861
# We don't want to return to unittest...
18611862
os._exit(0)
1863+
18621864
# Parent
18631865
os.close(w)
18641866
os.write(fd, terminal_input)
1867+
18651868
# Get results from the pipe
18661869
with open(r, "r") as rpipe:
18671870
lines = []
@@ -1871,6 +1874,7 @@ def run_child(self, child, terminal_input):
18711874
# The other end was closed => the child exited
18721875
break
18731876
lines.append(line)
1877+
18741878
# Check the result was got and corresponds to the user's terminal input
18751879
if len(lines) != 2:
18761880
# Something went wrong, try to get at stderr
@@ -1888,11 +1892,14 @@ def run_child(self, child, terminal_input):
18881892
child_output = child_output.decode("ascii", "ignore")
18891893
self.fail("got %d lines in pipe but expected 2, child output was:\n%s"
18901894
% (len(lines), child_output))
1891-
os.close(fd)
18921895

1893-
# Wait until the child process completes
1896+
# Wait until the child process completes before closing the PTY to
1897+
# prevent sending SIGHUP to the child process.
18941898
support.wait_process(pid, exitcode=0)
18951899

1900+
# Close the PTY
1901+
os.close(fd)
1902+
18961903
return lines
18971904

18981905
def check_input_tty(self, prompt, terminal_input, stdio_encoding=None):

0 commit comments

Comments
 (0)
0