Skip to content

Commit eacb85a

Browse files
gh-90092: Fix test_curses when stdin is write-only (e.g. under nohup) (GH-153420)
newterm() needs a readable input fd, but nohup can leave stdin write-only. Fall back to the output fd, as already done when stdin has no fileno. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent dd8739a commit eacb85a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/test/test_curses.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
except ImportError:
3030
pass
3131

32+
# Only reachable once curses imported, so the platform has fcntl too.
33+
import fcntl
34+
3235
def requires_curses_func(name):
3336
return unittest.skipUnless(hasattr(curses, name),
3437
'requires curses.%s' % name)
@@ -164,6 +167,10 @@ def setUp(self):
164167
# ScreenTests run newterm()/set_term() in the same process.
165168
try:
166169
infd = sys.__stdin__.fileno()
170+
if fcntl.fcntl(infd, fcntl.F_GETFL) & os.O_ACCMODE == os.O_WRONLY:
171+
# newterm() needs a readable input fd; a write-only stdin
172+
# (as nohup leaves for a backgrounded run) fails with EINVAL.
173+
infd = stdout_fd
167174
except (AttributeError, ValueError, OSError):
168175
infd = stdout_fd
169176
self.screen = curses.newterm(term, stdout_fd, infd)

0 commit comments

Comments
 (0)