summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-08-18 16:49:39 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-08-18 16:49:39 (GMT)
commit134a8baed9b70b2d6a953d0c872fc2c42580e1b6 (patch)
tree37beeda1725ef98a69e9e781e75eaa511c74f8ea /Lib/subprocess.py
parent5ad517a7d9c2694e726b3244505af274f91fb5d9 (diff)
downloadcpython-134a8baed9b70b2d6a953d0c872fc2c42580e1b6.zip
cpython-134a8baed9b70b2d6a953d0c872fc2c42580e1b6.tar.gz
cpython-134a8baed9b70b2d6a953d0c872fc2c42580e1b6.tar.bz2
Issue #12650: Fix a race condition where a subprocess.Popen could leak
resources (FD/zombie) when killed at the wrong time.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 2d85b50..017f58d 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -429,12 +429,16 @@ try:
except:
MAXFD = 256
+# This lists holds Popen instances for which the underlying process had not
+# exited at the time its __del__ method got called: those processes are wait()ed
+# for synchronously from _cleanup() when a new Popen object is created, to avoid
+# zombie processes.
_active = []
def _cleanup():
for inst in _active[:]:
res = inst._internal_poll(_deadstate=sys.maxsize)
- if res is not None and res >= 0:
+ if res is not None:
try:
_active.remove(inst)
except ValueError:
@@ -1191,6 +1195,7 @@ class Popen(object):
errread, errwrite,
errpipe_read, errpipe_write,
restore_signals, start_new_session, preexec_fn)
+ self._child_created = True
else:
# Pure Python implementation: It is not thread safe.
# This implementation may deadlock in the child if your