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

Function all_tasks

crates/stdlib/src/_asyncio.rs:2409–2447  ·  view source on GitHub ↗
(args: LoopArg, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2407
2408 #[pyfunction]
2409 fn all_tasks(args: LoopArg, vm: &VirtualMachine) -> PyResult {
2410 let loop_obj = match args.loop_.flatten() {
2411 Some(l) if !vm.is_none(&l) => l,
2412 _ => get_running_loop(vm)?,
2413 };
2414
2415 let all_tasks_set = get_all_tasks_set(vm)?;
2416 let result_set = PySet::default().into_ref(&vm.ctx);
2417
2418 let iter = vm.call_method(&all_tasks_set, "__iter__", ())?;
2419 loop {
2420 match vm.call_method(&iter, "__next__", ()) {
2421 Ok(task) => {
2422 // Try get_loop() method first, fallback to _loop property
2423 let task_loop = if let Ok(l) = vm.call_method(&task, "get_loop", ()) {
2424 Some(l)
2425 } else if let Ok(Some(l)) =
2426 vm.get_attribute_opt(task.clone(), vm.ctx.intern_str("_loop"))
2427 {
2428 Some(l)
2429 } else {
2430 None
2431 };
2432
2433 if let Some(task_loop) = task_loop
2434 && task_loop.is(&loop_obj)
2435 && let Ok(done) = vm.call_method(&task, "done", ())
2436 && !done.try_to_bool(vm).unwrap_or(true)
2437 {
2438 result_set.add(task, vm)?;
2439 }
2440 }
2441 Err(e) if e.fast_isinstance(vm.ctx.exceptions.stop_iteration) => break,
2442 Err(e) => return Err(e),
2443 }
2444 }
2445
2446 Ok(result_set.into())
2447 }
2448
2449 #[pyfunction]
2450 fn _register_task(task: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {

Callers

nothing calls this directly

Calls 15

get_all_tasks_setFunction · 0.85
get_attribute_optMethod · 0.80
intern_strMethod · 0.80
isMethod · 0.80
try_to_boolMethod · 0.80
fast_isinstanceMethod · 0.80
get_running_loopFunction · 0.70
SomeClass · 0.50
ErrClass · 0.50
flattenMethod · 0.45
is_noneMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected