From: Yonatan Goldschmidt Date: Tue, 25 May 2021 22:40:23 +0000 (+0300) Subject: bpo-44222: Improve _removeHandlerRef() for a very long _handlerList (GH-26325) X-Git-Tag: v3.11.0a1~1029 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=156699bca02dd2def844d03e26fc16a831336635;p=thirdparty%2FPython%2Fcpython.git bpo-44222: Improve _removeHandlerRef() for a very long _handlerList (GH-26325) The list lookups become a big burden for very long lists. This patch changes the "happy flow" path of 2 lookups into 1 lookup. Automerge-Triggered-By: GH:vsajip --- diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 555f598de7a9..7865b71c8737 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -845,8 +845,9 @@ def _removeHandlerRef(wr): if acquire and release and handlers: acquire() try: - if wr in handlers: - handlers.remove(wr) + handlers.remove(wr) + except ValueError: + pass finally: release()