diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-28 10:45:00 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-28 10:45:00 (GMT) |
commit | 86ba76570590b10ebd0b6f9b2e53252d8127de0e (patch) | |
tree | 721bdd46910e542d97e6ef038b73b08d46ca337f /Lib/subprocess.py | |
parent | 7e8c7956a7edc1505055d3dd9e5180fa30a3cab9 (diff) | |
parent | ab900c21fcfb08f13467d1c6f47d03ab90180f89 (diff) | |
download | cpython-86ba76570590b10ebd0b6f9b2e53252d8127de0e.zip cpython-86ba76570590b10ebd0b6f9b2e53252d8127de0e.tar.gz cpython-86ba76570590b10ebd0b6f9b2e53252d8127de0e.tar.bz2 |
Issue #21619: Popen objects no longer leave a zombie after exit in the with
statement if the pipe was broken. Patch by Martin Panter.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 25ffeff..6d2c4f5 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -892,10 +892,12 @@ class Popen(object): self.stdout.close() if self.stderr: self.stderr.close() - if self.stdin: - self.stdin.close() - # Wait for the process to terminate, to avoid zombies. - self.wait() + try: # Flushing a BufferedWriter may raise an error + if self.stdin: + self.stdin.close() + finally: + # Wait for the process to terminate, to avoid zombies. + self.wait() def __del__(self, _maxsize=sys.maxsize): if not self._child_created: |