]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43423 Fix IndexError in subprocess _communicate function (GH-24777)
authorChris Griffith <chris@cdgriffith.com>
Thu, 11 Mar 2021 19:43:29 +0000 (13:43 -0600)
committerGitHub <noreply@github.com>
Thu, 11 Mar 2021 19:43:29 +0000 (11:43 -0800)
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>
Lib/subprocess.py
Misc/NEWS.d/next/Library/2021-03-11-15-44-18.bpo-43423.rRomRD.rst [new file with mode: 0644]

index e4ca5f500c21a76fb09931fa8b420b7ce3678039..d375514b2dd0a6654b42130e99a972447fb9ba31 100644 (file)
@@ -1535,10 +1535,8 @@ class Popen(object):
                 self.stderr.close()
 
             # All data exchanged.  Translate lists into strings.
-            if stdout is not None:
-                stdout = stdout[0]
-            if stderr is not None:
-                stderr = stderr[0]
+            stdout = stdout[0] if stdout else None
+            stderr = stderr[0] if stderr else None
 
             return (stdout, stderr)
 
diff --git a/Misc/NEWS.d/next/Library/2021-03-11-15-44-18.bpo-43423.rRomRD.rst b/Misc/NEWS.d/next/Library/2021-03-11-15-44-18.bpo-43423.rRomRD.rst
new file mode 100644 (file)
index 0000000..290d7fb
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`subprocess.communicate` no longer raises an IndexError when there is an
+empty stdout or stderr IO buffer during a timeout on Windows.