summaryrefslogtreecommitdiff
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-01-19 22:29:41 +0000
committerGregory P. Smith <greg@mad-scientist.com>2008-01-19 22:29:41 +0000
commitc223c6cb413880842bf396153c237dd7f6eb619c (patch)
treebe4d2cd5238b4ee9667bade20dc522ec8afdf640 /Lib/subprocess.py
parentaf81c576ea441efb6c05aab31dc58b2792a5fdf2 (diff)
downloadcpython-git-c223c6cb413880842bf396153c237dd7f6eb619c.tar.gz
backport r60104 + r60111 from trunk.
- Issue #1336: fix a race condition in subprocess.Popen if the garbage collector kicked in at the wrong time that would cause the process to hang when the child wrote to stderr.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 5b6fb18289..094ca1ba88 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -358,6 +358,7 @@ mswindows = (sys.platform == "win32")
import os
import types
import traceback
+import gc
# Exception classes used by this module.
class CalledProcessError(Exception):
@@ -1002,7 +1003,16 @@ class Popen(object):
errpipe_read, errpipe_write = os.pipe()
self._set_cloexec_flag(errpipe_write)
- self.pid = os.fork()
+ gc_was_enabled = gc.isenabled()
+ # Disable gc to avoid bug where gc -> file_dealloc ->
+ # write to stderr -> hang. http://bugs.python.org/issue1336
+ gc.disable()
+ try:
+ self.pid = os.fork()
+ except:
+ if gc_was_enabled:
+ gc.enable()
+ raise
self._child_created = True
if self.pid == 0:
# Child
@@ -1062,6 +1072,8 @@ class Popen(object):
os._exit(255)
# Parent
+ if gc_was_enabled:
+ gc.enable()
os.close(errpipe_write)
if p2cread and p2cwrite:
os.close(p2cread)