summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2007-04-23 01:58:33 (GMT)
committerBarry Warsaw <barry@python.org>2007-04-23 01:58:33 (GMT)
commit2f131d81e2c45c4a2a8bebd0eded737bc90de965 (patch)
tree362b77d90f5674a6dadcc0ada9aebd5dfca9a836
parentb9d39916ac8a23949c7abf95fe832376f44dce99 (diff)
downloadcpython-2f131d81e2c45c4a2a8bebd0eded737bc90de965.zip
cpython-2f131d81e2c45c4a2a8bebd0eded737bc90de965.tar.gz
cpython-2f131d81e2c45c4a2a8bebd0eded737bc90de965.tar.bz2
Recommit r54805:
Add code to read from master_fd in the parent, breaking when we get an OSError (EIO can occur on Linux) or there's no more data to read. Without this, test_pty.py can hang on the waitpid() because the child is blocking on the stdout write. This will definitely happen on Mac OS X and could potentially happen on other platforms. See the comment for details.
-rw-r--r--Lib/test/test_pty.py18
-rw-r--r--Misc/NEWS3
2 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index 02290be..e69d7ea 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -115,6 +115,24 @@ if pid == pty.CHILD:
os._exit(4)
else:
debug("Waiting for child (%d) to finish."%pid)
+ # In verbose mode, we have to consume the debug output from the child or
+ # the child will block, causing this test to hang in the parent's
+ # waitpid() call. The child blocks after a platform-dependent amount of
+ # data is written to its fd. On Linux 2.6, it's 4000 bytes and the child
+ # won't block, but on OS X even the small writes in the child above will
+ # block it. Also on Linux, the read() will throw an OSError (input/output
+ # error) when it tries to read past the end of the buffer but the child's
+ # already exited, so catch and discard those exceptions. It's not worth
+ # checking for EIO.
+ while True:
+ try:
+ data = os.read(master_fd, 80)
+ except OSError:
+ break
+ if not data:
+ break
+ sys.stdout.write(data.replace('\r\n', '\n'))
+
##line = os.read(master_fd, 80)
##lines = line.replace('\r\n', '\n').split('\n')
##if False and lines != ['In child, calling os.setsid()',
diff --git a/Misc/NEWS b/Misc/NEWS
index a089275..1d1ef10 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,9 @@ Library
- tarfile.py: Fix directory names to have only one trailing slash.
+- Fix test_pty.py to not hang on OS X (and theoretically other *nixes) when
+ run in verbose mode.
+
What's New in Python 2.5.1?
=============================