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

Function _leave_task

crates/stdlib/src/_asyncio.rs:2503–2527  ·  view source on GitHub ↗
(loop_: PyObjectRef, task: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2501
2502 #[pyfunction]
2503 fn _leave_task(loop_: PyObjectRef, task: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
2504 // Per-thread check, matching CPython's ts->asyncio_running_task
2505 {
2506 let running_task = vm.asyncio_running_task.borrow();
2507 match running_task.as_ref() {
2508 None => {
2509 return Err(vm.new_runtime_error("_leave_task: task is not the current task"));
2510 }
2511 Some(current) if !current.is(&task) => {
2512 return Err(vm.new_runtime_error("_leave_task: task is not the current task"));
2513 }
2514 _ => {}
2515 }
2516 }
2517
2518 *vm.asyncio_running_task.borrow_mut() = None;
2519
2520 // Also update the module-level dict
2521 if let Ok(current_tasks) = get_current_tasks_dict(vm)
2522 && let Ok(dict) = current_tasks.downcast::<rustpython_vm::builtins::PyDict>()
2523 {
2524 let _ = dict.del_item(&*loop_, vm);
2525 }
2526 Ok(())
2527 }
2528
2529 #[pyfunction]
2530 fn _swap_current_task(loop_: PyObjectRef, task: PyObjectRef, vm: &VirtualMachine) -> PyResult {

Callers 1

task_step_implFunction · 0.70

Calls 7

get_current_tasks_dictFunction · 0.85
isMethod · 0.80
borrow_mutMethod · 0.80
ErrClass · 0.50
borrowMethod · 0.45
as_refMethod · 0.45
del_itemMethod · 0.45

Tested by

no test coverage detected