Skip to content

Commit

Permalink
Replace ctrlc crate with tokio (#2207)
Browse files Browse the repository at this point in the history
* Replace ctrlc crate with tokio signals

* Don't treat SIGTERM as a crash
  • Loading branch information
emilk committed May 25, 2023
1 parent 5d685a9 commit af42993
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
12 changes: 1 addition & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ cfg-if = "1.0"
clap = "4.0"
comfy-table = { version = "6.1", default-features = false }
crossbeam = "0.8"
ctrlc = { version = "3.0", features = ["termination"] }
ecolor = "0.22.0"
eframe = { version = "0.22.0", default-features = false }
egui = { version = "0.22.0", features = ["extra_debug_asserts", "log"] }
Expand Down
1 change: 0 additions & 1 deletion crates/rerun/src/crash_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ fn install_signal_handler(build_info: BuildInfo) {
libc::SIGFPE,
libc::SIGILL,
libc::SIGSEGV,
libc::SIGTERM,
] {
// SAFETY: we're installing a signal handler.
unsafe {
Expand Down
3 changes: 1 addition & 2 deletions rerun_py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ re_web_viewer_server = { workspace = true, optional = true }
re_ws_comms = { workspace = true, optional = true }

arrow2 = { workspace = true, features = ["io_ipc", "io_print"] }
ctrlc.workspace = true
document-features = "0.2"
glam.workspace = true
image = { workspace = true, default-features = false, features = [
Expand All @@ -64,7 +63,7 @@ once_cell = "1.12"
parking_lot = "0.12"
pyo3 = { version = "0.18.0", features = ["abi3-py38"] }
rand = { version = "0.8", features = ["std_rng"] }
tokio = { workspace = true, features = ["rt-multi-thread"] }
tokio = { workspace = true, features = ["rt-multi-thread", "signal"] }
uuid = "1.1"


Expand Down
22 changes: 12 additions & 10 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,24 @@ fn global_web_viewer_server(

#[pyfunction]
fn main(py: Python<'_>, argv: Vec<String>) -> PyResult<u8> {
// Python catches SIGINT and waits for us to release the GIL before shtting down.
// That's no good, so we need to catch SIGINT ourselves and shut down:
ctrlc::set_handler(move || {
eprintln!("Ctrl-C detected in rerun_py. Shutting down.");
#[allow(clippy::exit)]
std::process::exit(42);
})
.expect("Error setting Ctrl-C handler");

let build_info = re_build_info::build_info!();
let call_src = rerun::CallSource::Python(python_version(py));
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(rerun::run(build_info, call_src, argv))
.block_on(async {
// Python catches SIGINT and waits for us to release the GIL before shtting down.
// That's no good, so we need to catch SIGINT ourselves and shut down:
tokio::spawn(async move {
tokio::signal::ctrl_c().await.unwrap();
eprintln!("Ctrl-C detected in rerun_py. Shutting down.");
#[allow(clippy::exit)]
std::process::exit(42);
});

rerun::run(build_info, call_src, argv).await
})
.map_err(|err| PyRuntimeError::new_err(re_error::format(err)))
}

Expand Down

0 comments on commit af42993

Please sign in to comment.