Skip to content

Commit 5e390a0

Browse files
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]>
1 parent c8cf5d7 commit 5e390a0

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Lib/threading.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os as _os
44
import sys as _sys
55
import _thread
6-
import functools
76
import warnings
87

98
from time import monotonic as _time
@@ -1630,8 +1629,7 @@ def _register_atexit(func, *arg, **kwargs):
16301629
if _SHUTTING_DOWN:
16311630
raise RuntimeError("can't register atexit after shutdown")
16321631

1633-
call = functools.partial(func, *arg, **kwargs)
1634-
_threading_atexits.append(call)
1632+
_threading_atexits.append(lambda: func(*arg, **kwargs))
16351633

16361634

16371635
from _thread import stack_size
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reduce the import time of :mod:`threading` module by ~50%. Patch by Daniel Hollas.

0 commit comments

Comments
 (0)