diff options
author | Charles-François Natali <neologix@free.fr> | 2011-08-18 17:11:29 (GMT) |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2011-08-18 17:11:29 (GMT) |
commit | 558639f0c9cc507acafd0c3842a23d03b2244652 (patch) | |
tree | 6fe7f3f1eca5ad431164b89aad298523b43f504c /Lib/subprocess.py | |
parent | 020340f2841ec2b70b9e09921850d16019d0667e (diff) | |
parent | 134a8baed9b70b2d6a953d0c872fc2c42580e1b6 (diff) | |
download | cpython-558639f0c9cc507acafd0c3842a23d03b2244652.zip cpython-558639f0c9cc507acafd0c3842a23d03b2244652.tar.gz cpython-558639f0c9cc507acafd0c3842a23d03b2244652.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.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index ec417c2..db64588 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -424,12 +424,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: @@ -1272,6 +1276,7 @@ class Popen(object): errread, errwrite, errpipe_read, errpipe_write, restore_signals, start_new_session, preexec_fn) + self._child_created = True finally: # be sure the FD is closed no matter what os.close(errpipe_write) |