mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Issue #21619: Popen objects no longer leave a zombie after exit in the with
statement if the pipe was broken. Patch by Martin Panter.
This commit is contained in:
parent
fdde79dbf6
commit
ab900c21fc
3 changed files with 24 additions and 4 deletions
|
|
@ -896,8 +896,10 @@ class Popen(object):
|
|||
self.stdout.close()
|
||||
if self.stderr:
|
||||
self.stderr.close()
|
||||
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()
|
||||
|
||||
|
|
|
|||
|
|
@ -2521,6 +2521,21 @@ class ContextManagerTests(BaseTestCase):
|
|||
stderr=subprocess.PIPE) as proc:
|
||||
pass
|
||||
|
||||
def test_broken_pipe_cleanup(self):
|
||||
"""Broken pipe error should not prevent wait() (Issue 21619)"""
|
||||
proc = subprocess.Popen([sys.executable, "-c",
|
||||
"import sys;"
|
||||
"sys.stdin.close();"
|
||||
"sys.stdout.close();" # Signals that input pipe is closed
|
||||
], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
proc.stdout.read() # Make sure subprocess has closed its input
|
||||
proc.stdin.write(b"buffered data")
|
||||
self.assertIsNone(proc.returncode)
|
||||
self.assertRaises(BrokenPipeError, proc.__exit__, None, None, None)
|
||||
self.assertEqual(0, proc.returncode)
|
||||
self.assertTrue(proc.stdin.closed)
|
||||
self.assertTrue(proc.stdout.closed)
|
||||
|
||||
|
||||
def test_main():
|
||||
unit_tests = (ProcessTestCase,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #21619: Popen objects no longer leave a zombie after exit in the with
|
||||
statement if the pipe was broken. Patch by Martin Panter.
|
||||
|
||||
- Issue #6639: Module-level turtle functions no longer raise TclError after
|
||||
closing the window.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue