From 9daeaecd6c605db39103a1252fcbbf56e42cc339 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 17 Aug 2022 01:59:10 +0900 Subject: [PATCH] _thread compatibility using frozen _dummy_thread --- Lib/functools.py | 5 +---- Lib/reprlib.py | 5 +---- Lib/tempfile.py | 5 +---- Lib/zipfile.py | 2 +- vm/Lib/python_builtins/_thread.py | 1 + vm/src/vm/mod.rs | 2 ++ 6 files changed, 7 insertions(+), 13 deletions(-) create mode 120000 vm/Lib/python_builtins/_thread.py diff --git a/Lib/functools.py b/Lib/functools.py index 74db9969ad..8decc874e1 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -18,10 +18,7 @@ from abc import get_cache_token from collections import namedtuple # import types, weakref # Deferred to single_dispatch() from reprlib import recursive_repr -try: - from _thread import RLock -except ModuleNotFoundError: - from _dummy_thread import RLock +from _thread import RLock from types import GenericAlias diff --git a/Lib/reprlib.py b/Lib/reprlib.py index 6b0283b793..616b3439b5 100644 --- a/Lib/reprlib.py +++ b/Lib/reprlib.py @@ -4,10 +4,7 @@ __all__ = ["Repr", "repr", "recursive_repr"] import builtins from itertools import islice -try: - from _thread import get_ident -except ModuleNotFoundError: - from _dummy_thread import get_ident +from _thread import get_ident def recursive_repr(fillvalue='...'): 'Decorator to make a repr function return fillvalue for a recursive call' diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 17b380c290..3aceb3f70f 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -47,10 +47,7 @@ import sys as _sys import types as _types import weakref as _weakref -try: - import _thread -except ImportError: - import _dummy_thread as _thread +import _thread _allocate_lock = _thread.allocate_lock _text_openflags = _os.O_RDWR | _os.O_CREAT | _os.O_EXCL diff --git a/Lib/zipfile.py b/Lib/zipfile.py index d94310164d..ef1eb47f9f 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -22,7 +22,7 @@ import sys try: import threading except ImportError: - import _dummy_thread as threading + import dummy_threading as threading import time import contextlib import pathlib diff --git a/vm/Lib/python_builtins/_thread.py b/vm/Lib/python_builtins/_thread.py new file mode 120000 index 0000000000..fa4a34c4fb --- /dev/null +++ b/vm/Lib/python_builtins/_thread.py @@ -0,0 +1 @@ +../../../Lib/_dummy_thread.py \ No newline at end of file diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs index e98ec694d5..526239e8ff 100644 --- a/vm/src/vm/mod.rs +++ b/vm/src/vm/mod.rs @@ -233,6 +233,8 @@ impl VirtualMachine { let mut essential_init = || -> PyResult { #[cfg(not(target_arch = "wasm32"))] import::import_builtin(self, "_signal")?; + #[cfg(not(feature = "threading"))] + import::import_frozen(self, "_thread")?; let importlib = import::init_importlib_base(self)?; self.import_utf8_encodings()?;