Skip to content

Commit 228f977

Browse files
Close the pty master before the slave in ScreenTests
On macOS, closing the pty slave while the master is still open blocks until the slave's pending output drains. Closing the master first stops the reader thread and leaves nothing for the slave close to wait for. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6d48237 commit 228f977

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Lib/test/test_curses.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,16 +1795,17 @@ def _drain_pty(master):
17951795

17961796
def make_pty(self):
17971797
master, slave = os.openpty()
1798-
# Nothing reads the master end, so writing to the slave -- and the
1799-
# tcdrain() inside endwin() -- can block once the pty buffer fills (on
1800-
# macOS, not Linux). Drain it from a background thread; endwin()
1801-
# releases the GIL so the thread runs while endwin() blocks.
1798+
# Nothing reads the master end, so writing to the slave and the
1799+
# tcdrain() in endwin() can block on macOS once the pty buffer fills;
1800+
# drain it from a background thread (endwin() releases the GIL).
18021801
reader = threading.Thread(target=self._drain_pty, args=(master,),
18031802
daemon=True)
18041803
reader.start()
18051804
self.addCleanup(reader.join, SHORT_TIMEOUT)
1806-
self.addCleanup(os.close, master)
1805+
# Close the master first (cleanups run in reverse): on macOS, closing
1806+
# the slave first blocks until its pending output drains.
18071807
self.addCleanup(os.close, slave)
1808+
self.addCleanup(os.close, master)
18081809
return slave
18091810

18101811
def test_newterm(self):

0 commit comments

Comments
 (0)