Skip to content

Commit

Permalink
gh-109653: Speedup import of threading module (#114509)
Browse files Browse the repository at this point in the history
Avoiding an import of functools leads to 50% speedup of import time.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
danielhollas and AlexWaygood committed Jan 31, 2024
1 parent c8cf5d7 commit 5e390a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os as _os
import sys as _sys
import _thread
import functools
import warnings

from time import monotonic as _time
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reduce the import time of :mod:`threading` module by ~50%. Patch by Daniel Hollas.

0 comments on commit 5e390a0

Please sign in to comment.