From ee994255d96cc0f261d848796ab36ab94593f4ec Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 10 Jul 2024 23:15:03 +0000 Subject: [PATCH] gh-121605: Increase timeout in test_pyrepl.run_repl We also need to close the `slave_fd` earlier so that reading from `master_fd` won't block forever when the subprocess finishes. --- Lib/test/test_pyrepl/test_pyrepl.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index 015b690566223d..a4848beb147199 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -942,20 +942,23 @@ def run_repl(self, repl_input: str | list[str], env: dict | None = None) -> tupl text=True, close_fds=True, env=env if env else os.environ, - ) + ) + os.close(slave_fd) if isinstance(repl_input, list): repl_input = "\n".join(repl_input) + "\n" os.write(master_fd, repl_input.encode("utf-8")) output = [] - while select.select([master_fd], [], [], 0.5)[0]: - data = os.read(master_fd, 1024).decode("utf-8") - if not data: + while select.select([master_fd], [], [], SHORT_TIMEOUT)[0]: + try: + data = os.read(master_fd, 1024).decode("utf-8") + if not data: + break + except OSError: break output.append(data) os.close(master_fd) - os.close(slave_fd) try: exit_code = process.wait(timeout=SHORT_TIMEOUT) except subprocess.TimeoutExpired: