Skip to content

Commit 0b98c18

Browse files
committed
Disable _thread on wasm
1 parent 56cfd83 commit 0b98c18

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Lib/importlib/_bootstrap.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,12 +1149,21 @@ def _setup(sys_module, _imp_module):
11491149

11501150
# Directly load built-in modules needed during bootstrap.
11511151
self_module = sys.modules[__name__]
1152-
for builtin_name in ('_thread', '_warnings', '_weakref'):
1152+
for builtin_name in ('_warnings', '_weakref'):
11531153
if builtin_name not in sys.modules:
11541154
builtin_module = _builtin_from_name(builtin_name)
11551155
else:
11561156
builtin_module = sys.modules[builtin_name]
11571157
setattr(self_module, builtin_name, builtin_module)
1158+
# _thread was part of the above loop, but other parts of the code allow for it
1159+
# to be None, so we handle it separately here
1160+
builtin_name = '_thread'
1161+
if builtin_name in sys.modules:
1162+
builtin_module = sys.modules[builtin_name]
1163+
else:
1164+
builtin_spec = BuiltinImporter.find_spec(builtin_name)
1165+
builtin_module = builtin_spec and _load_unlocked(builtin_spec)
1166+
setattr(self_module, builtin_name, builtin_module)
11581167

11591168

11601169
def _install(sys_module, _imp_module):

vm/src/stdlib/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub mod socket;
3030
mod string;
3131
#[cfg(feature = "rustpython-compiler")]
3232
mod symtable;
33+
#[cfg(not(target_arch = "wasm32"))]
3334
mod thread;
3435
mod time_module;
3536
#[cfg(feature = "rustpython-parser")]
@@ -89,7 +90,6 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
8990
"_random".to_owned() => Box::new(random::make_module),
9091
"_string".to_owned() => Box::new(string::make_module),
9192
"_struct".to_owned() => Box::new(pystruct::make_module),
92-
"_thread".to_owned() => Box::new(thread::make_module),
9393
"time".to_owned() => Box::new(time_module::make_module),
9494
"_weakref".to_owned() => Box::new(weakref::make_module),
9595
"_imp".to_owned() => Box::new(imp::make_module),
@@ -130,6 +130,7 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
130130
#[cfg(feature = "ssl")]
131131
modules.insert("_ssl".to_owned(), Box::new(ssl::make_module));
132132
modules.insert("_subprocess".to_owned(), Box::new(subprocess::make_module));
133+
modules.insert("_thread".to_owned(), Box::new(thread::make_module));
133134
#[cfg(not(target_os = "redox"))]
134135
modules.insert("zlib".to_owned(), Box::new(zlib::make_module));
135136
modules.insert(

0 commit comments

Comments
 (0)