aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-28 12:43:08 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-28 12:43:08 +0200
commitab900c21fcfb08f13467d1c6f47d03ab90180f89 (patch)
treed2585129064d0de2bdb03aec77e790e89305de40 /Lib/subprocess.py
parentFix the clarification as to why division cannot be ported automatically (diff)
downloadcpython-ab900c21fcfb08f13467d1c6f47d03ab90180f89.tar.gz
cpython-ab900c21fcfb08f13467d1c6f47d03ab90180f89.tar.bz2
cpython-ab900c21fcfb08f13467d1c6f47d03ab90180f89.zip
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.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index bc0ef0b4bea..f11e538925b 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -896,10 +896,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: