Skip to content

gh-89386: Lib/pty.py: handle stdin I/O errors same way as master I/O errors - #28388

Open
kanavin wants to merge 3 commits into
python:mainfrom
kanavin:fix-pty-spawn
Open

kanavin wants to merge 3 commits into
python:mainfrom
kanavin:fix-pty-spawn

Conversation

@kanavin

@kanavin kanavin commented Sep 16, 2021 •

Copy link
Copy Markdown
Contributor

reading stdin can throw the same I/O errors as reading from master fd does,
e.g. when running under Yocto's test harness:

ERROR: test_spawn_doesnt_hang (test.test_pty.PtyTest)

Traceback (most recent call last):
File "/usr/lib/python3.10/test/test_pty.py", line 316, in test_spawn_doesnt_hang
pty.spawn([sys.executable, '-c', 'print("hi there")'])
File "/usr/lib/python3.10/pty.py", line 181, in spawn
_copy(master_fd, master_read, stdin_read)
File "/usr/lib/python3.10/pty.py", line 157, in _copy
data = stdin_read(STDIN_FILENO)
File "/usr/lib/python3.10/pty.py", line 132, in _read
return os.read(fd, 1024)
OSError: [Errno 5] Input/output error

So let's treat both channels the same.

Signed-off-by: Alexander Kanavin alex@linutronix.de

https://bugs.python.org/issue45223

@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@kanavin

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Oct 17, 2021
@kanavin

kanavin commented Nov 5, 2021

Copy link
Copy Markdown
Contributor Author

Just signed the CLA, will check in a few days if it's active.

@CoolCat467

Copy link
Copy Markdown
Contributor

@kanavin Just checked now and it still says no

@kanavin

kanavin commented Nov 11, 2021

Copy link
Copy Markdown
Contributor Author

@kanavin Just checked now and it still says no

If i type @kanavin into https://check-python-cla.herokuapp.com/ I get 500 Internal server error. How did you check?

@CoolCat467

Copy link
Copy Markdown
Contributor

Need to use kanavin, without @ symbol

@kanavin

kanavin commented Nov 22, 2021

Copy link
Copy Markdown
Contributor Author

Need to use kanavin, without @ symbol

Right, I had it set on bpo with @. I removed that, and it looks good now.

@MaxwellDupre MaxwellDupre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good:
Ran 7 tests in 0.049s

OK (expected failures=1)

== Tests result: SUCCESS ==

@netlify

netlify Bot commented Dec 6, 2022 •

Copy link
Copy Markdown

✅ Deploy Preview for python-cpython-preview canceled.

Name Link
🔨 Latest commit 3c3c3bb
🔍 Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/63905060686239000ad92955

reading stdin can throw the same I/O errors as reading from master fd does,
e.g. when running under Yocto's test harness:
======================================================================
ERROR: test_spawn_doesnt_hang (test.test_pty.PtyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.10/test/test_pty.py", line 316, in test_spawn_doesnt_hang
    pty.spawn([sys.executable, '-c', 'print("hi there")'])
  File "/usr/lib/python3.10/pty.py", line 181, in spawn
    _copy(master_fd, master_read, stdin_read)
  File "/usr/lib/python3.10/pty.py", line 157, in _copy
    data = stdin_read(STDIN_FILENO)
  File "/usr/lib/python3.10/pty.py", line 132, in _read
    return os.read(fd, 1024)
OSError: [Errno 5] Input/output error

So let's treat both channels the same.

Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
@furkanonder

Copy link
Copy Markdown
Contributor

@kanavin Can you explain the way to reproduce the error? I would like to try this in my local and check if the error still exists.

@kanavin

kanavin commented May 9, 2023

Copy link
Copy Markdown
Contributor Author

@kanavin Can you explain the way to reproduce the error? I would like to try this in my local and check if the error still exists.

We use this to run the tests:
https://git.yoctoproject.org/ptest-runner2/tree/

I just confirmed: when running python3 -m test.test_pty -v directly on the terminal it passes. When the same command is executed by ptest-runner with i/o handled by it, it fails as shown above.

@python python deleted a comment Apr 7, 2025
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Apr 9, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 11, 2026
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Aug 12, 2026
@serhiy-storchaka serhiy-storchaka changed the title bpo-45223: Lib/pty.py: handle stdin I/O errors same way as master I/O errors gh-89386: Lib/pty.py: handle stdin I/O errors same way as master I/O errors Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants