Skip to content

Commit e4a9a67

Browse files
ambvpicnixz
andauthored
Apply suggestions from code review
Co-authored-by: Bénédikt Tran <[email protected]>
1 parent d0f9659 commit e4a9a67

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

Lib/test/test_pyrepl/eio_test_script.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import errno
2+
import fcntl
13
import os
2-
import sys
34
import pty
4-
import fcntl
5-
import termios
65
import signal
7-
import errno
6+
import sys
7+
import termios
88

99

1010
def handler(sig, f):
1111
pass
1212

1313

1414
def create_eio_condition():
15+
# SIGINT handler used to produce an EIO.
16+
# See https://github.com/python/cpython/issues/135329.
1517
try:
16-
# gh-135329: try to create a condition that will actually produce EIO
1718
master_fd, slave_fd = pty.openpty()
1819
child_pid = os.fork()
1920
if child_pid == 0:
@@ -23,19 +24,14 @@ def create_eio_condition():
2324
p2_pgid = os.getpgrp()
2425
grandchild_pid = os.fork()
2526
if grandchild_pid == 0:
26-
# Grandchild - set up process group
27-
os.setpgid(0, 0)
28-
# Redirect stdin to slave
29-
os.dup2(slave_fd, 0)
27+
os.setpgid(0, 0) # set process group for grandchild
28+
os.dup2(slave_fd, 0) # redirect stdin
3029
if slave_fd > 2:
3130
os.close(slave_fd)
32-
# Fork great-grandchild for terminal control manipulation
33-
ggc_pid = os.fork()
34-
if ggc_pid == 0:
35-
# Great-grandchild - just exit quickly
36-
sys.exit(0)
31+
# Fork grandchild for terminal control manipulation
32+
if os.fork() == 0:
33+
sys.exit(0) # exit the child process that was just obtained
3734
else:
38-
# Back to grandchild
3935
try:
4036
os.tcsetpgrp(0, p2_pgid)
4137
except OSError:
@@ -71,8 +67,7 @@ def create_eio_condition():
7167
os.dup2(master_fd, 0)
7268
os.close(master_fd)
7369
# This should now trigger EIO
74-
result = input()
75-
print(f"Unexpectedly got input: {repr(result)}", file=sys.stderr)
70+
print(f"Unexpectedly got input: {input()!r}", file=sys.stderr)
7671
sys.exit(0)
7772
except OSError as e:
7873
if e.errno == errno.EIO:

Lib/test/test_pyrepl/test_unix_console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,6 @@ def test_repl_eio(self):
358358
self.fail("Child process failed to start properly")
359359

360360
os.kill(proc.pid, signal.SIGUSR1)
361-
_, err = proc.communicate(timeout=5) # sleep for pty to settle
361+
_, err = proc.communicate(timeout=5) # sleep for pty to settle
362362
self.assertEqual(proc.returncode, 1, f"Expected EIO error, got return code {proc.returncode}")
363363
self.assertIn("Got EIO:", err, f"Expected EIO error message in stderr: {err}")

0 commit comments

Comments
 (0)