summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pty.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2007-04-13 18:47:14 (GMT)
committerBarry Warsaw <barry@python.org>2007-04-13 18:47:14 (GMT)
commit25a3864541dc9259a3bfd36b195cbb764f8e2d56 (patch)
tree5bf4185d754518590dc92ba63407ac19d47ef0c6 /Lib/test/test_pty.py
parent4234827e99eb73adbd387e15619cd6290f80f655 (diff)
downloadcpython-25a3864541dc9259a3bfd36b195cbb764f8e2d56.zip
cpython-25a3864541dc9259a3bfd36b195cbb764f8e2d56.tar.gz
cpython-25a3864541dc9259a3bfd36b195cbb764f8e2d56.tar.bz2
Port r54805 from python25-maint branch:
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.
Diffstat (limited to 'Lib/test/test_pty.py')
-rw-r--r--Lib/test/test_pty.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
index bfa624f..11fff34 100644
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -1,5 +1,6 @@
import pty
import os
+import sys
import signal
from test.test_support import verbose, TestSkipped, run_unittest
import unittest
@@ -120,6 +121,25 @@ class PtyTest(unittest.TestCase):
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()',