[Python-checkins] gh-96349: fix minor performance regression initializing threading.Event (gh-96350)

corona10 webhook-mailer at python.org
Tue Aug 30 08:10:11 EDT 2022


https://github.com/python/cpython/commit/22ed5233b76fe33f9767c6a5665608e7f398e7d7
commit: 22ed5233b76fe33f9767c6a5665608e7f398e7d7
branch: main
author: Daniel Giger <danielg1111 at verizon.net>
committer: corona10 <donghee.na92 at gmail.com>
date: 2022-08-30T21:10:02+09:00
summary:

gh-96349: fix minor performance regression initializing threading.Event (gh-96350)

files:
A Misc/NEWS.d/next/Library/2022-08-27-21-26-52.gh-issue-96349.XyYLlO.rst
M Lib/threading.py

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__`



More information about the Python-checkins mailing list