(loop_: PyObjectRef, task: PyObjectRef, vm: &VirtualMachine)
| 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 { |
no test coverage detected