blob: 026150f0e2437e4d040499ba05ba2b06c35a35b9 [file] [log] [blame]
Patrick Williams56b44a92024-01-19 08:49:29 -06001From f8a664cf1fc73e381d57d6927207286059744837 Mon Sep 17 00:00:00 2001
Andrew Geisslereff27472021-10-29 15:35:00 -05002From: Alexander Kanavin <alex@linutronix.de>
3Date: Thu, 16 Sep 2021 16:35:37 +0200
4Subject: [PATCH] Lib/pty.py: handle stdin I/O errors same way as master I/O
5 errors
6
7reading stdin can throw the same I/O errors as reading from master fd does,
8e.g. when running under Yocto's test harness:
9======================================================================
10ERROR: test_spawn_doesnt_hang (test.test_pty.PtyTest)
11----------------------------------------------------------------------
12Traceback (most recent call last):
13 File "/usr/lib/python3.10/test/test_pty.py", line 316, in test_spawn_doesnt_hang
14 pty.spawn([sys.executable, '-c', 'print("hi there")'])
15 File "/usr/lib/python3.10/pty.py", line 181, in spawn
16 _copy(master_fd, master_read, stdin_read)
17 File "/usr/lib/python3.10/pty.py", line 157, in _copy
18 data = stdin_read(STDIN_FILENO)
19 File "/usr/lib/python3.10/pty.py", line 132, in _read
20 return os.read(fd, 1024)
21OSError: [Errno 5] Input/output error
22
23So let's treat both channels the same.
24
25Upstream-Status: Submitted [https://github.com/python/cpython/pull/28388]
26Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Andrew Geissler595f6302022-01-24 19:11:47 +000027
Andrew Geisslereff27472021-10-29 15:35:00 -050028---
29 Lib/pty.py | 5 ++++-
30 1 file changed, 4 insertions(+), 1 deletion(-)
31
32diff --git a/Lib/pty.py b/Lib/pty.py
Patrick Williams56b44a92024-01-19 08:49:29 -060033index 1d97994..fa8821b 100644
Andrew Geisslereff27472021-10-29 15:35:00 -050034--- a/Lib/pty.py
35+++ b/Lib/pty.py
Patrick Williams56b44a92024-01-19 08:49:29 -060036@@ -178,7 +178,10 @@ def _copy(master_fd, master_read=_read, stdin_read=_read):
Andrew Geissler8f840682023-07-21 09:09:43 -050037 i_buf = i_buf[n:]
Andrew Geisslereff27472021-10-29 15:35:00 -050038
Andrew Geissler8f840682023-07-21 09:09:43 -050039 if stdin_avail and STDIN_FILENO in rfds:
Andrew Geisslereff27472021-10-29 15:35:00 -050040- data = stdin_read(STDIN_FILENO)
41+ try:
42+ data = stdin_read(STDIN_FILENO)
43+ except OSError:
44+ data = b""
45 if not data:
Andrew Geissler8f840682023-07-21 09:09:43 -050046 stdin_avail = False
Andrew Geisslereff27472021-10-29 15:35:00 -050047 else: