MCPcopy Index your code
hub / github.com/RustPython/RustPython / import_ensure_initialized

Function import_ensure_initialized

crates/vm/src/import.rs:158–175  ·  view source on GitHub ↗

If `__spec__._initializing` is true, wait for the module to finish initializing by calling `_lock_unlock_module`.

(
    module: &PyObjectRef,
    name: &str,
    vm: &VirtualMachine,
)

Source from the content-addressed store, hash-verified

156/// If `__spec__._initializing` is true, wait for the module to finish
157/// initializing by calling `_lock_unlock_module`.
158fn import_ensure_initialized(
159 module: &PyObjectRef,
160 name: &str,
161 vm: &VirtualMachine,
162) -> PyResult<()> {
163 let initializing = match vm.get_attribute_opt(module.clone(), vm.ctx.intern_str("__spec__"))? {
164 Some(spec) => match vm.get_attribute_opt(spec, vm.ctx.intern_str("_initializing"))? {
165 Some(v) => v.try_to_bool(vm)?,
166 None => false,
167 },
168 None => false,
169 };
170 if initializing {
171 let lock_unlock = vm.importlib.get_attr("_lock_unlock_module", vm)?;
172 lock_unlock.call((vm.ctx.new_utf8_str(name),), vm)?;
173 }
174 Ok(())
175}
176
177pub fn import_code_obj(
178 vm: &VirtualMachine,

Callers 1

import_module_levelFunction · 0.85

Calls 7

get_attribute_optMethod · 0.80
intern_strMethod · 0.80
try_to_boolMethod · 0.80
new_utf8_strMethod · 0.80
cloneMethod · 0.45
get_attrMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected