Skip to main content

Module interrupt

Module interrupt 

Source
Expand description

User-initiated cooperative cancellation (Ctrl-C / SIGINT).

Long-running CLI builds (notably dense embedding via CUDA) spend most of their time inside ONNX Runtime FFI (session.run()). If the default SIGINT disposition kills the process mid-kernel, the CUDA context is never torn down cleanly: the process lingers as a zombie and its VRAM stays allocated until the driver reclaims it (observed under WSL2 GPU passthrough).

This module installs a cooperative SIGINT handler: the first Ctrl-C only flips a global flag. Cancellable loops poll is_cancelled between FFI calls and return early, so control is back in Rust code — not inside a CUDA kernel — when the process exits. That lets the driver reclaim VRAM on a clean exit. A second Ctrl-C forces an immediate _exit for the impatient.

The handler body only performs async-signal-safe operations (atomic stores and, on the second signal, libc::_exit).

Functions§

install_ctrlc_handler
Install the cooperative SIGINT handler (idempotent).
is_cancelled
true once the user has requested cancellation via Ctrl-C.
reset
Clear the cancellation state before starting a fresh cancellable operation.