Skip to content

Conversation

@ctb
Copy link
Collaborator

@ctb ctb commented Jul 12, 2024

@ctb
Copy link
Collaborator Author

ctb commented Jul 12, 2024

Main problem right now - can't use py.check_signals() inside a closure 🤔

@bluegenes
Copy link
Contributor

FYI we can use the rust ctrlc crate, see:

static TERMINATE_FLAG: OnceLock<Arc<AtomicBool>> = OnceLock::new();
static CTRL_HANDLER_INIT: Once = Once::new();
pub fn setup_ctrlc_handler() -> Arc<AtomicBool> {
let flag = TERMINATE_FLAG.get_or_init(|| Arc::new(AtomicBool::new(false)));
CTRL_HANDLER_INIT.call_once(|| {
let flag_clone = Arc::clone(flag);
let _ = ctrlc::set_handler(move || {
eprintln!("Received Ctrl-C, requesting shutdown...");
flag_clone.store(true, Ordering::SeqCst);
});
});
Arc::clone(flag)
}

(pass in the cancel_flag anywhere it is needed; check regularly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enable CTRL-C in rust code?

3 participants