If `__spec__._initializing` is true, wait for the module to finish initializing by calling `_lock_unlock_module`.
(
module: &PyObjectRef,
name: &str,
vm: &VirtualMachine,
)
| 156 | /// If `__spec__._initializing` is true, wait for the module to finish |
| 157 | /// initializing by calling `_lock_unlock_module`. |
| 158 | fn 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 | |
| 177 | pub fn import_code_obj( |
| 178 | vm: &VirtualMachine, |
no test coverage detected