polars_error/
signals.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::PolarsResult;

type SignalsFunction = fn() -> PolarsResult<()>;
static mut SIGNALS_FUNCTION: Option<SignalsFunction> = None;

/// Set the function that will be called check_signals.
/// This can be set on startup to enable stopping a query when user input like `ctrl-c` is called.
///
/// # Safety
/// The caller must ensure there is no other thread accessing this function
/// or calling `check_signals`.
pub unsafe fn set_signals_function(function: SignalsFunction) {
    SIGNALS_FUNCTION = Some(function)
}

fn default() -> PolarsResult<()> {
    Ok(())
}

pub fn check_signals() -> PolarsResult<()> {
    let f = unsafe { SIGNALS_FUNCTION.unwrap_or(default) };
    f()
}