From 3b3dfac2c16a3f229f69180fc769583f21e3b6c6 Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Fri, 31 Mar 2017 15:15:10 +0200 Subject: [PATCH] Avoid pip.main leaking loggers - fixes #3043 --- pip/basecommand.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pip/basecommand.py b/pip/basecommand.py index 6ba36069558..2c17c92c689 100644 --- a/pip/basecommand.py +++ b/pip/basecommand.py @@ -210,6 +210,8 @@ def main(self, args): ) sys.exit(VIRTUALENV_NOT_FOUND) + original_root_handlers = set(logging.root.handlers) + try: status = self.run(options, args) # FIXME: all commands should return an exit status @@ -249,6 +251,10 @@ def main(self, args): retries=0, timeout=min(5, options.timeout)) as session: pip_version_check(session, options) + # Avoid leaking loggers + for handler in set(logging.root.handlers) - original_root_handlers: + # this method benefit from the Logger class internal lock + logging.root.removeHandler(handler) return SUCCESS