polars_error/
signals.rs

1use crate::PolarsResult;
2
3type SignalsFunction = fn() -> PolarsResult<()>;
4static mut SIGNALS_FUNCTION: Option<SignalsFunction> = None;
5
6/// Set the function that will be called check_signals.
7/// This can be set on startup to enable stopping a query when user input like `ctrl-c` is called.
8///
9/// # Safety
10/// The caller must ensure there is no other thread accessing this function
11/// or calling `check_signals`.
12pub unsafe fn set_signals_function(function: SignalsFunction) {
13    SIGNALS_FUNCTION = Some(function)
14}
15
16fn default() -> PolarsResult<()> {
17    Ok(())
18}
19
20pub fn check_signals() -> PolarsResult<()> {
21    let f = unsafe { SIGNALS_FUNCTION.unwrap_or(default) };
22    f()
23}