| 67 | |
| 68 | #[pyfunction] |
| 69 | pub fn _run_exitfuncs(vm: &VirtualMachine) { |
| 70 | let funcs: Vec<_> = core::mem::take(&mut *vm.state.atexit_funcs.lock()); |
| 71 | // Callbacks stored in LIFO order, iterate forward |
| 72 | for entry in funcs.into_iter() { |
| 73 | let (func, args) = *entry; |
| 74 | if let Err(e) = func.call(args, vm) { |
| 75 | let exit = e.fast_isinstance(vm.ctx.exceptions.system_exit); |
| 76 | let msg = func |
| 77 | .repr(vm) |
| 78 | .ok() |
| 79 | .map(|r| format!("Exception ignored in atexit callback {}", r.as_wtf8())); |
| 80 | vm.run_unraisable(e, msg, vm.ctx.none()); |
| 81 | if exit { |
| 82 | break; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | #[pyfunction] |
| 89 | fn _ncallbacks(vm: &VirtualMachine) -> usize { |