summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/importlib/util.py4
-rw-r--r--Misc/NEWS.d/next/Library/2024-06-07-10-10-32.gh-issue-117983.NeMR9n.rst2
2 files changed, 5 insertions, 1 deletions
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py
index 7243d05..8403ef9 100644
--- a/Lib/importlib/util.py
+++ b/Lib/importlib/util.py
@@ -13,7 +13,6 @@ from ._bootstrap_external import spec_from_file_location
import _imp
import sys
-import threading
import types
@@ -257,6 +256,9 @@ class LazyLoader(Loader):
def exec_module(self, module):
"""Make the module load lazily."""
+ # Threading is only needed for lazy loading, and importlib.util can
+ # be pulled in at interpreter startup, so defer until needed.
+ import threading
module.__spec__.loader = self.loader
module.__loader__ = self.loader
# Don't need to worry about deep-copying as trying to set an attribute
diff --git a/Misc/NEWS.d/next/Library/2024-06-07-10-10-32.gh-issue-117983.NeMR9n.rst b/Misc/NEWS.d/next/Library/2024-06-07-10-10-32.gh-issue-117983.NeMR9n.rst
new file mode 100644
index 0000000..cca97f5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-06-07-10-10-32.gh-issue-117983.NeMR9n.rst
@@ -0,0 +1,2 @@
+Defer the ``threading`` import in ``importlib.util`` until lazy loading is
+used.