From 8662248774fae518b35f1ec5fdc437c0ae68b4bc Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 21 Nov 2020 07:20:19 -0800 Subject: [PATCH] Always close stderr after subprocess completion in call_subprocess() When running Python with warnings enabled, fixes warnings of the form: .../site-packages/pip/_internal/vcs/versioncontrol.py:773: ResourceWarning: unclosed file <_io.BufferedReader name=12> return call_subprocess(cmd, cwd, --- news/9156.bugfix.rst | 1 + src/pip/_internal/vcs/versioncontrol.py | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 news/9156.bugfix.rst diff --git a/news/9156.bugfix.rst b/news/9156.bugfix.rst new file mode 100644 index 00000000000..9b433fae2fc --- /dev/null +++ b/news/9156.bugfix.rst @@ -0,0 +1 @@ +Fix ResourceWarning in VCS subprocesses diff --git a/src/pip/_internal/vcs/versioncontrol.py b/src/pip/_internal/vcs/versioncontrol.py index 219f7967319..6724dcc697d 100644 --- a/src/pip/_internal/vcs/versioncontrol.py +++ b/src/pip/_internal/vcs/versioncontrol.py @@ -150,6 +150,8 @@ def call_subprocess( finally: if proc.stdout: proc.stdout.close() + if proc.stderr: + proc.stderr.close() proc_had_error = ( proc.returncode and proc.returncode not in extra_ok_returncodes