]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96349: fix minor performance regression initializing threading.Event (gh-96350)
authorDaniel Giger <danielg1111@verizon.net>
Tue, 30 Aug 2022 12:10:02 +0000 (08:10 -0400)
committerGitHub <noreply@github.com>
Tue, 30 Aug 2022 12:10:02 +0000 (21:10 +0900)
Lib/threading.py
Misc/NEWS.d/next/Library/2022-08-27-21-26-52.gh-issue-96349.XyYLlO.rst [new file with mode: 0644]

index 7237a149ecca2e5925ae94a64ad25bea99ac8cda..d030e1243623f981bdd3a63e82179365b5ce63dd 100644 (file)
@@ -262,18 +262,12 @@ class Condition:
         # 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 (file)
index 0000000..59eb351
--- /dev/null
@@ -0,0 +1 @@
+Fixed a minor performance regression in :func:`threading.Event.__init__`