Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Bénédikt Tran <[email protected]>
  • Loading branch information
ambv and picnixz authored Sep 16, 2025
commit e4a9a67660d80ad26e5ae35e60827eebfe9ba110
29 changes: 12 additions & 17 deletions Lib/test/test_pyrepl/eio_test_script.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import errno
import fcntl
import os
import sys
import pty
import fcntl
import termios
import signal
import errno
import sys
import termios


def handler(sig, f):
pass


def create_eio_condition():
Comment thread
ambv marked this conversation as resolved.
# SIGINT handler used to produce an EIO.
# See https://github.com/python/cpython/issues/135329.
try:
# gh-135329: try to create a condition that will actually produce EIO
master_fd, slave_fd = pty.openpty()
child_pid = os.fork()
if child_pid == 0:
Expand All @@ -23,19 +24,14 @@ def create_eio_condition():
p2_pgid = os.getpgrp()
Comment thread
ambv marked this conversation as resolved.
Outdated
grandchild_pid = os.fork()
if grandchild_pid == 0:
# Grandchild - set up process group
os.setpgid(0, 0)
# Redirect stdin to slave
os.dup2(slave_fd, 0)
os.setpgid(0, 0) # set process group for grandchild
os.dup2(slave_fd, 0) # redirect stdin
if slave_fd > 2:
os.close(slave_fd)
# Fork great-grandchild for terminal control manipulation
ggc_pid = os.fork()
if ggc_pid == 0:
# Great-grandchild - just exit quickly
sys.exit(0)
# Fork grandchild for terminal control manipulation
if os.fork() == 0:
sys.exit(0) # exit the child process that was just obtained
else:
# Back to grandchild
try:
os.tcsetpgrp(0, p2_pgid)
except OSError:
Expand Down Expand Up @@ -71,8 +67,7 @@ def create_eio_condition():
os.dup2(master_fd, 0)
os.close(master_fd)
# This should now trigger EIO
result = input()
print(f"Unexpectedly got input: {repr(result)}", file=sys.stderr)
print(f"Unexpectedly got input: {input()!r}", file=sys.stderr)
sys.exit(0)
except OSError as e:
if e.errno == errno.EIO:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_pyrepl/test_unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,6 @@ def test_repl_eio(self):
self.fail("Child process failed to start properly")

os.kill(proc.pid, signal.SIGUSR1)
_, err = proc.communicate(timeout=5) # sleep for pty to settle
_, err = proc.communicate(timeout=5) # sleep for pty to settle
self.assertEqual(proc.returncode, 1, f"Expected EIO error, got return code {proc.returncode}")
self.assertIn("Got EIO:", err, f"Expected EIO error message in stderr: {err}")
Comment thread
ambv marked this conversation as resolved.
Outdated
Loading