diff --git a/Cargo.toml b/Cargo.toml index 5a854a41e..e5218ef5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -138,7 +138,7 @@ tempfile = { version = "3.9.0" } textwrap = { version = "0.16.1" } thiserror = { version = "1.0.56" } tl = { version = "0.7.7" } -tokio = { version = "1.35.1", features = ["fs", "io-util", "macros", "process", "sync"] } +tokio = { version = "1.35.1", features = ["fs", "io-util", "macros", "process", "signal", "sync"] } tokio-stream = { version = "0.1.14" } tokio-tar = { version = "0.3.1" } tokio-util = { version = "0.7.10", features = ["compat"] } diff --git a/crates/uv/src/commands/project/run.rs b/crates/uv/src/commands/project/run.rs index 59313d6ee..69d8a6c4e 100644 --- a/crates/uv/src/commands/project/run.rs +++ b/crates/uv/src/commands/project/run.rs @@ -471,6 +471,12 @@ pub(crate) async fn run( command.executable().to_string_lossy() ) })?; + + // Ignore signals in the parent process, deferring them to the child. This is safe as long as + // the command is the last thing that runs in this process; otherwise, we'd need to restore the + // signal handlers after the command completes. + let _handler = tokio::spawn(async { while tokio::signal::ctrl_c().await.is_ok() {} }); + let status = handle.wait().await.context("Child process disappeared")?; // Exit based on the result of the command diff --git a/crates/uv/src/commands/tool/run.rs b/crates/uv/src/commands/tool/run.rs index 7fc47a18b..f0c335150 100644 --- a/crates/uv/src/commands/tool/run.rs +++ b/crates/uv/src/commands/tool/run.rs @@ -185,6 +185,11 @@ pub(crate) async fn run( } .with_context(|| format!("Failed to spawn: `{}`", executable.to_string_lossy()))?; + // Ignore signals in the parent process, deferring them to the child. This is safe as long as + // the command is the last thing that runs in this process; otherwise, we'd need to restore the + // signal handlers after the command completes. + let _handler = tokio::spawn(async { while tokio::signal::ctrl_c().await.is_ok() {} }); + let status = handle.wait().await.context("Child process disappeared")?; // Exit based on the result of the command