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

Function module_exec

crates/stdlib/src/_asyncio.rs:32–60  ·  view source on GitHub ↗
(vm: &VirtualMachine, module: &Py<PyModule>)

Source from the content-addressed store, hash-verified

30 use crossbeam_utils::atomic::AtomicCell;
31
32 pub(crate) fn module_exec(vm: &VirtualMachine, module: &Py<PyModule>) -> PyResult<()> {
33 __module_exec(vm, module);
34
35 // Initialize module-level state
36 let weakref_module = vm.import("weakref", 0)?;
37 let weak_set_class = vm
38 .get_attribute_opt(weakref_module, vm.ctx.intern_str("WeakSet"))?
39 .ok_or_else(|| vm.new_attribute_error("WeakSet not found"))?;
40 let scheduled_tasks = weak_set_class.call((), vm)?;
41 let eager_tasks = PySet::default().into_ref(&vm.ctx);
42 let current_tasks = PyDict::default().into_ref(&vm.ctx);
43
44 extend_module!(vm, module, {
45 "_scheduled_tasks" => scheduled_tasks,
46 "_eager_tasks" => eager_tasks,
47 "_current_tasks" => current_tasks,
48 });
49
50 // Register fork handler to clear task state in child process
51 #[cfg(unix)]
52 {
53 let on_fork = vm
54 .get_attribute_opt(module.to_owned().into(), vm.ctx.intern_str("_on_fork"))?
55 .expect("_on_fork not found in _asyncio module");
56 vm.state.after_forkers_child.lock().push(on_fork);
57 }
58
59 Ok(())
60 }
61
62 #[derive(FromArgs)]
63 struct AddDoneCallbackArgs {

Callers

nothing calls this directly

Calls 9

ok_or_elseMethod · 0.80
get_attribute_optMethod · 0.80
intern_strMethod · 0.80
importMethod · 0.45
callMethod · 0.45
into_refMethod · 0.45
to_ownedMethod · 0.45
pushMethod · 0.45
lockMethod · 0.45

Tested by

no test coverage detected