Skip to content

Commit abc3aee

Browse files
authored
gh-121605: Increase timeout in test_pyrepl.run_repl (#121606)
We also need to close the `slave_fd` earlier so that reading from `master_fd` won't block forever when the subprocess finishes.
1 parent 0a26aa5 commit abc3aee

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Lib/test/test_pyrepl/test_pyrepl.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -981,20 +981,23 @@ def run_repl(self, repl_input: str | list[str], env: dict | None = None) -> tupl
981981
text=True,
982982
close_fds=True,
983983
env=env if env else os.environ,
984-
)
984+
)
985+
os.close(slave_fd)
985986
if isinstance(repl_input, list):
986987
repl_input = "\n".join(repl_input) + "\n"
987988
os.write(master_fd, repl_input.encode("utf-8"))
988989

989990
output = []
990-
while select.select([master_fd], [], [], 0.5)[0]:
991-
data = os.read(master_fd, 1024).decode("utf-8")
992-
if not data:
991+
while select.select([master_fd], [], [], SHORT_TIMEOUT)[0]:
992+
try:
993+
data = os.read(master_fd, 1024).decode("utf-8")
994+
if not data:
995+
break
996+
except OSError:
993997
break
994998
output.append(data)
995999

9961000
os.close(master_fd)
997-
os.close(slave_fd)
9981001
try:
9991002
exit_code = process.wait(timeout=SHORT_TIMEOUT)
10001003
except subprocess.TimeoutExpired:

0 commit comments

Comments
 (0)