SpawnProcess: read proc with unbuffered fdopen
authorZac Medico <zmedico@gentoo.org>
Fri, 21 Jan 2011 02:14:26 +0000 (18:14 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 21 Jan 2011 02:14:26 +0000 (18:14 -0800)
This enables pty support in python3, by using unbuffered fdopen to avoid
http://bugs.python.org/issue5380.

pym/_emerge/SpawnProcess.py
pym/portage/tests/ebuild/test_pty_eof.py
pym/portage/util/_pty.py

index 0cddbe801cd29e6dfa3ff7ce808f02d011abfec8..bc861e9c5e0bdf563883bdbd16920f01686f5ee5 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2010 Gentoo Foundation
+# Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.SubProcess import SubProcess
@@ -72,7 +72,9 @@ class SpawnProcess(SubProcess):
                else:
                        fd_pipes[0] = fd_pipes_orig[0]
 
-               files.process = os.fdopen(master_fd, 'rb')
+               # WARNING: It is very important to use unbuffered mode here,
+               # in order to avoid issue 5380 with python3.
+               files.process = os.fdopen(master_fd, 'rb', 0)
                if logfile is not None:
 
                        fd_pipes[1] = slave_fd
index c4386e944e7dfcb00c4a58d1adf640b27feac385..251b63c439a9ca78c8d5bb34531bcf771f1a0388 100644 (file)
@@ -14,7 +14,7 @@ class PtyEofTestCase(TestCase):
                # The result is only valid if openpty does not raise EnvironmentError.
                if _can_test_pty_eof():
                        try:
-                               self.assertEqual(_test_pty_eof(), True)
+                               self.assertEqual(_test_pty_eof(fdopen_buffered=True), True)
                        except EnvironmentError:
                                pass
 
@@ -26,6 +26,6 @@ class PtyEofTestCase(TestCase):
                # The result is only valid if openpty does not raise EnvironmentError.
                if _can_test_pty_eof():
                        try:
-                               self.assertEqual(_test_pty_eof(fdopen_buffered=False), True)
+                               self.assertEqual(_test_pty_eof(), True)
                        except EnvironmentError:
                                pass
index 7e769d204db2368184375f8a3f0afb41a6ad037a..c96bf74fd0a9fc33975632279b28fe4f431bffc5 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import array
@@ -28,7 +28,7 @@ def _can_test_pty_eof():
        """
        return platform.system() in ("Linux",)
 
-def _test_pty_eof(fdopen_buffered=True):
+def _test_pty_eof(fdopen_buffered=False):
        """
        Returns True if this issues is fixed for the currently
        running version of python: http://bugs.python.org/issue5380