https://github.com/python/cpython/commit/5e390a0fc825f21952beb158e2bda3c5e007fac9
commit: 5e390a0fc825f21952beb158e2bda3c5e007fac9
branch: main
author: Daniel Hollas <[email protected]>
committer: AlexWaygood <[email protected]>
date: 2024-01-31T09:29:44Z
summary:

gh-109653: Speedup import of threading module (#114509)

Avoiding an import of functools leads to 50% speedup of import time.

Co-authored-by: Alex Waygood <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-01-23-23-13-47.gh-issue-109653.KLBHmT.rst
M Lib/threading.py

diff --git a/Lib/threading.py b/Lib/threading.py
index 00b95f8d92a1f0..75a08e5aac97d6 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -3,7 +3,6 @@
 import os as _os
 import sys as _sys
 import _thread
-import functools
 import warnings
 
 from time import monotonic as _time
@@ -1630,8 +1629,7 @@ def _register_atexit(func, *arg, **kwargs):
     if _SHUTTING_DOWN:
         raise RuntimeError("can't register atexit after shutdown")
 
-    call = functools.partial(func, *arg, **kwargs)
-    _threading_atexits.append(call)
+    _threading_atexits.append(lambda: func(*arg, **kwargs))
 
 
 from _thread import stack_size
diff --git 
a/Misc/NEWS.d/next/Library/2024-01-23-23-13-47.gh-issue-109653.KLBHmT.rst 
b/Misc/NEWS.d/next/Library/2024-01-23-23-13-47.gh-issue-109653.KLBHmT.rst
new file mode 100644
index 00000000000000..76074df9c76fa6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-01-23-23-13-47.gh-issue-109653.KLBHmT.rst
@@ -0,0 +1 @@
+Reduce the import time of :mod:`threading` module by ~50%. Patch by Daniel 
Hollas.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to