(args: DumpTracebackLaterArgs, vm: &VirtualMachine)
| 905 | |
| 906 | #[pyfunction] |
| 907 | fn dump_traceback_later(args: DumpTracebackLaterArgs, vm: &VirtualMachine) -> PyResult<()> { |
| 908 | let timeout: f64 = args.timeout.into_float(); |
| 909 | |
| 910 | if timeout <= 0.0 { |
| 911 | return Err(vm.new_value_error("timeout must be greater than 0")); |
| 912 | } |
| 913 | |
| 914 | let fd = get_fd_from_file_opt(args.file, vm)?; |
| 915 | |
| 916 | // Convert timeout to microseconds |
| 917 | let timeout_us = (timeout * 1_000_000.0) as u64; |
| 918 | if timeout_us == 0 { |
| 919 | return Err(vm.new_value_error("timeout must be greater than 0")); |
| 920 | } |
| 921 | |
| 922 | let header = format_timeout(timeout_us); |
| 923 | |
| 924 | // Snapshot thread frame slots so watchdog can dump tracebacks |
| 925 | #[cfg(feature = "threading")] |
| 926 | let thread_frame_slots: Vec<(u64, ThreadFrameSlot)> = { |
| 927 | let registry = vm.state.thread_frames.lock(); |
| 928 | registry |
| 929 | .iter() |
| 930 | .map(|(&id, slot)| (id, Arc::clone(slot))) |
| 931 | .collect() |
| 932 | }; |
| 933 | |
| 934 | // Cancel any previous watchdog |
| 935 | cancel_dump_traceback_later(); |
| 936 | |
| 937 | // Create new watchdog state |
| 938 | let state = Arc::new(( |
| 939 | Mutex::new(WatchdogState { |
| 940 | cancel: false, |
| 941 | fd, |
| 942 | timeout_us, |
| 943 | repeat: args.repeat, |
| 944 | exit: args.exit, |
| 945 | header, |
| 946 | #[cfg(feature = "threading")] |
| 947 | thread_frame_slots, |
| 948 | }), |
| 949 | Condvar::new(), |
| 950 | )); |
| 951 | |
| 952 | // Store the state |
| 953 | { |
| 954 | let mut watchdog = WATCHDOG.lock(); |
| 955 | *watchdog = Some(Arc::clone(&state)); |
| 956 | } |
| 957 | |
| 958 | // Start watchdog thread |
| 959 | thread::spawn(move || { |
| 960 | watchdog_thread(state); |
| 961 | }); |
| 962 | |
| 963 | Ok(()) |
| 964 | } |
nothing calls this directly
no test coverage detected