Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ctrlc crate with tokio #2207

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -52,7 +52,6 @@ re_ws_comms = { workspace = true, optional = true }
re_viewer = { workspace = 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 @@ -67,7 +66,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 @@ -72,22 +72,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