10000 bpo-31160: Fix race condition in test_os.PtyTests by vstinner · Pull Request #19263 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-31160: Fix race condition in test_os.PtyTests #19263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,7 @@ def run_child(self, child, terminal_input):
os.close(w)
self.skipTest("pty.fork() raised {}".format(e))
raise

if pid == 0:
# Child
try:
Expand All @@ -1859,9 +1860,11 @@ def run_child(self, child, terminal_input):
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 = []
Expand All @@ -1871,6 +1874,7 @@ def run_child(self, child, terminal_input):
# 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
Expand All @@ -1888,11 +1892,14 @@ def run_child(self, child, terminal_input):
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):
Expand Down
0