Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.12] gh-117983: Defer import of threading for lazy module loading (GH-120233) #121350

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/importlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import _imp
import sys
import threading
import types


Expand Down Expand Up @@ -253,6 +252,9 @@ def create_module(self, spec):

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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Defer the ``threading`` import in ``importlib.util`` until lazy loading is
used.
Loading