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

Function dump_traceback_later

crates/stdlib/src/faulthandler.rs:907–964  ·  view source on GitHub ↗
(args: DumpTracebackLaterArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

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 }

Callers

nothing calls this directly

Calls 13

get_fd_from_file_optFunction · 0.85
format_timeoutFunction · 0.85
newFunction · 0.85
watchdog_threadFunction · 0.85
into_floatMethod · 0.80
collectMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
spawnFunction · 0.50
lockMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected