Skip to content

Commit 1a5001c

Browse files
bpo-43423 Fix IndexError in subprocess _communicate function (GH-24777)
Check to make sure stdout and stderr are not empty before selecting an item from them in Windows subprocess._communicate. Co-authored-by: Gregory P. Smith <[email protected]> (cherry picked from commit b4fc44b) Co-authored-by: Chris Griffith <[email protected]>
1 parent ac5e23c commit 1a5001c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Lib/subprocess.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,10 +1416,8 @@ def _communicate(self, input, endtime, orig_timeout):
14161416
self.stderr.close()
14171417

14181418
# All data exchanged. Translate lists into strings.
1419-
if stdout is not None:
1420-
stdout = stdout[0]
1421-
if stderr is not None:
1422-
stderr = stderr[0]
1419+
stdout = stdout[0] if stdout else None
1420+
stderr = stderr[0] if stderr else None
14231421

14241422
return (stdout, stderr)
14251423

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`subprocess.communicate` no longer raises an IndexError when there is an
2+
empty stdout or stderr IO buffer during a timeout on Windows.

0 commit comments

Comments
 (0)