From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 12 Mar 2021 01:56:35 +0000 (-0800) Subject: bpo-43423 Fix IndexError in subprocess _communicate function (GH-24777) X-Git-Tag: v3.9.3~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ad83fde75463dad2df878ff264f52436eb48bc6b;p=thirdparty%2FPython%2Fcpython.git 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 (cherry picked from commit b4fc44bb2d209182390b4f9fdf074a46b0165a2f) Co-authored-by: Chris Griffith --- diff --git a/Lib/subprocess.py b/Lib/subprocess.py index ddf1128fdd1c..0311e3a1f83e 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1525,10 +1525,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 index 000000000000..290d7fbd9180 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-03-11-15-44-18.bpo-43423.rRomRD.rst @@ -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.