From 22ed5233b76fe33f9767c6a5665608e7f398e7d7 Mon Sep 17 00:00:00 2001 From: Daniel Giger Date: Tue, 30 Aug 2022 08:10:02 -0400 Subject: [PATCH] gh-96349: fix minor performance regression initializing threading.Event (gh-96350) --- Lib/threading.py | 12 +++--------- .../2022-08-27-21-26-52.gh-issue-96349.XyYLlO.rst | 1 + 2 files changed, 4 insertions(+), 9 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-08-27-21-26-52.gh-issue-96349.XyYLlO.rst diff --git a/Lib/threading.py b/Lib/threading.py index 7237a149ecc..d030e124362 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -262,18 +262,12 @@ def __init__(self, lock=None): # If the lock defines _release_save() and/or _acquire_restore(), # these override the default implementations (which just call # release() and acquire() on the lock). Ditto for _is_owned(). - try: + if hasattr(lock, '_release_save'): self._release_save = lock._release_save - except AttributeError: - pass - try: + if hasattr(lock, '_acquire_restore'): self._acquire_restore = lock._acquire_restore - except AttributeError: - pass - try: + if hasattr(lock, '_is_owned'): self._is_owned = lock._is_owned - except AttributeError: - pass self._waiters = _deque() def _at_fork_reinit(self): diff --git a/Misc/NEWS.d/next/Library/2022-08-27-21-26-52.gh-issue-96349.XyYLlO.rst b/Misc/NEWS.d/next/Library/2022-08-27-21-26-52.gh-issue-96349.XyYLlO.rst new file mode 100644 index 00000000000..59eb3517191 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-08-27-21-26-52.gh-issue-96349.XyYLlO.rst @@ -0,0 +1 @@ +Fixed a minor performance regression in :func:`threading.Event.__init__`