[issue11432] webbrowser.open on unix fails.

Charles-Francois Natali report at bugs.python.org
Tue Mar 8 21:17:19 CET 2011


Charles-Francois Natali <neologix at free.fr> added the comment:

Attached is a patch checking that no FD is closed more once when
closing pipe FDs, along with an update for test_subprocess.

----------
keywords: +patch
Added file: http://bugs.python.org/file21053/subprocess_same_fd.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11432>
_______________________________________
-------------- next part --------------
Index: Lib/test/test_subprocess.py
===================================================================
--- Lib/test/test_subprocess.py	(révision 88766)
+++ Lib/test/test_subprocess.py	(copie de travail)
@@ -292,6 +292,32 @@
         tf.seek(0)
         self.assertStderrEqual(tf.read(), b"appleorange")
 
+    def test_stdin_stdout_filedes(self):
+        # capture stdin and stdout to the same open file
+        tf = tempfile.TemporaryFile()
+        self.addCleanup(tf.close)
+        p = subprocess.Popen([sys.executable, "-c",
+                              'import sys;'
+                              'sys.stdout.write("apple");'],
+                             stdin=tf,
+                             stdout=tf)
+        p.wait()
+        tf.seek(0)
+        self.assertEqual(tf.read(), b"apple")
+
+    def test_stdin_stderr_filedes(self):
+        # capture stdin and stderr to the same open file
+        tf = tempfile.TemporaryFile()
+        self.addCleanup(tf.close)
+        p = subprocess.Popen([sys.executable, "-c",
+                              'import sys;'
+                              'sys.stderr.write("apple");'],
+                             stdin=tf,
+                             stderr=tf)
+        p.wait()
+        tf.seek(0)
+        self.assertEqual(tf.read(), b"apple")
+
     def test_stdout_filedes_of_stdout(self):
         # stdout is set to 1 (#1531862).
         cmd = r"import sys, os; sys.exit(os.write(sys.stdout.fileno(), b'.\n'))"
Index: Modules/_posixsubprocess.c
===================================================================
--- Modules/_posixsubprocess.c	(révision 88766)
+++ Modules/_posixsubprocess.c	(copie de travail)
@@ -99,10 +99,10 @@
     if (p2cread > 2) {
         POSIX_CALL(close(p2cread));
     }
-    if (c2pwrite > 2) {
+    if (c2pwrite > 2 && c2pwrite != p2cread) {
         POSIX_CALL(close(c2pwrite));
     }
-    if (errwrite != c2pwrite && errwrite > 2) {
+    if (errwrite > 2 && errwrite != c2pwrite && errwrite != p2cread) {
         POSIX_CALL(close(errwrite));
     }
 


More information about the Python-bugs-list mailing list