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

Function task_step_handle_exception

crates/stdlib/src/_asyncio.rs:2237–2283  ·  view source on GitHub ↗
(
        task: &PyRef<PyTask>,
        exc: PyBaseExceptionRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

2235 }
2236
2237 fn task_step_handle_exception(
2238 task: &PyRef<PyTask>,
2239 exc: PyBaseExceptionRef,
2240 vm: &VirtualMachine,
2241 ) -> PyResult<()> {
2242 // Check for KeyboardInterrupt or SystemExit - these should be re-raised
2243 let should_reraise = exc.fast_isinstance(vm.ctx.exceptions.keyboard_interrupt)
2244 || exc.fast_isinstance(vm.ctx.exceptions.system_exit);
2245
2246 if exc.fast_isinstance(vm.ctx.exceptions.stop_iteration) {
2247 // Check if task was cancelled while running
2248 if task.task_must_cancel.load(Ordering::Relaxed) {
2249 // Task was cancelled - treat as cancelled instead of result
2250 task.task_must_cancel.store(false, Ordering::Relaxed);
2251 let cancelled_exc = task.base.make_cancelled_error_impl(vm);
2252 task.base.fut_state.store(FutureState::Cancelled);
2253 *task.base.fut_cancelled_exc.write() = Some(cancelled_exc.into());
2254 } else {
2255 let result = exc.get_arg(0).unwrap_or_else(|| vm.ctx.none());
2256 task.base.fut_state.store(FutureState::Finished);
2257 *task.base.fut_result.write() = Some(result);
2258 }
2259 PyTask::schedule_callbacks(task, vm)?;
2260 _unregister_task(task.clone().into(), vm)?;
2261 } else if is_cancelled_error(&exc, vm) {
2262 task.base.fut_state.store(FutureState::Cancelled);
2263 *task.base.fut_cancelled_exc.write() = Some(exc.clone().into());
2264 PyTask::schedule_callbacks(task, vm)?;
2265 _unregister_task(task.clone().into(), vm)?;
2266 } else {
2267 task.base.fut_state.store(FutureState::Finished);
2268 // Save the original traceback for later restoration
2269 let tb = exc.__traceback__().map(|tb| tb.into());
2270 *task.base.fut_exception_tb.write() = tb;
2271 *task.base.fut_exception.write() = Some(exc.clone().into());
2272 task.base.fut_log_tb.store(true, Ordering::Relaxed);
2273 PyTask::schedule_callbacks(task, vm)?;
2274 _unregister_task(task.clone().into(), vm)?;
2275 }
2276
2277 // Re-raise KeyboardInterrupt and SystemExit after storing in task
2278 if should_reraise {
2279 return Err(exc);
2280 }
2281
2282 Ok(())
2283 }
2284
2285 fn task_wakeup_impl(task: &PyObjectRef, fut: &PyObjectRef, vm: &VirtualMachine) -> PyResult {
2286 let task_ref: PyRef<PyTask> = task

Callers 2

task_eager_startFunction · 0.85
task_step_implFunction · 0.85

Calls 14

is_cancelled_errorFunction · 0.85
fast_isinstanceMethod · 0.80
noneMethod · 0.80
__traceback__Method · 0.80
_unregister_taskFunction · 0.70
SomeClass · 0.50
ErrClass · 0.50
loadMethod · 0.45
storeMethod · 0.45
writeMethod · 0.45
get_argMethod · 0.45

Tested by

no test coverage detected