mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-35182: fix communicate() crash after child closes its pipes (GH-17020) (GH-18117)
When communicate() is called in a loop, it crashes when the child process has already closed any piped standard stream, but still continues to be running Co-authored-by: Andriy Maletsky <andriy.maletsky@gmail.com>
This commit is contained in:
parent
1f0f102dec
commit
d3ae95e1e9
3 changed files with 16 additions and 2 deletions
|
@ -3145,6 +3145,17 @@ class POSIXProcessTestCase(BaseTestCase):
|
|||
# so Popen failed to read it and uses a default returncode instead.
|
||||
self.assertIsNotNone(proc.returncode)
|
||||
|
||||
def test_communicate_repeated_call_after_stdout_close(self):
|
||||
proc = subprocess.Popen([sys.executable, '-c',
|
||||
'import os, time; os.close(1), time.sleep(2)'],
|
||||
stdout=subprocess.PIPE)
|
||||
while True:
|
||||
try:
|
||||
proc.communicate(timeout=0.1)
|
||||
return
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
|
||||
|
||||
@unittest.skipUnless(mswindows, "Windows specific tests")
|
||||
class Win32ProcessTestCase(BaseTestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue