[issue15408] os.fork/os.popen behaviour change between 2.7 and 3.2
Richard Oudkerk
report at bugs.python.org
Mon Jul 23 20:20:41 CEST 2012
Richard Oudkerk <shibturn at gmail.com> added the comment:
A program which depends on the old behaviour would be broken on a non-refcounted implementation of Python, so I would be inclined to say "won't fix".
However, I think the following patch would restore the old behaviour
diff -r a970054a93fb Lib/os.py
--- a/Lib/os.py Mon Jul 16 18:30:03 2012 +0100
+++ b/Lib/os.py Mon Jul 23 19:12:38 2012 +0100
@@ -1004,6 +1004,13 @@
# Helper for popen() -- a proxy for a file whose close waits for the process
class _wrap_close:
def __init__(self, stream, proc):
+ # proc should be waited on when stream is garbage collected
+ import weakref
+ def callback(wr):
+ proc._weakref = None # break ref cycle
+ proc.wait()
+ proc._weakref = weakref.ref(stream, callback)
+ proc.stdin = proc.stdout = None # proc must not keep stream alive
self._stream = stream
self._proc = proc
def close(self):
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15408>
_______________________________________
More information about the Python-bugs-list
mailing list