8000 bpo-43423 Fix IndexError in subprocess _communicate function (GH-24777) · python/cpython@b4fc44b · GitHub
[go: up one dir, main page]

Skip to content

Commit b4fc44b

Browse files
cdgriffithgpshead
andauthored
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 <greg@krypto.org>
1 parent 87f649a commit b4fc44b

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
@@ -1535,10 +1535,8 @@ def _communicate(self, input, endtime, orig_timeout):
15351535
self.stderr.close()
15361536

15371537
# All data exchanged. Translate lists into strings.
1538-
if stdout is not None:
1539-
stdout = stdout[0]
1540-
if stderr is not None:
1541-
stderr = stderr[0]
1538+
stdout = stdout[0] if stdout else None
1539+
stderr = stderr[0] if stderr else None
15421540

15431541
return (stdout, stderr)
15441542

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)
0