Merge pull request #4475 from discord9/pr_no_ctrl_c

feat: allow specifying an implementation flag so as to not set SIGINT handler
This commit is contained in:
Jim Fasarakis-Hilliard
2023-01-31 12:24:01 +02:00
committed by GitHub
3 changed files with 10 additions and 1 deletions

View File

@@ -245,6 +245,9 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) {
if name == "warn_default_encoding" {
warn_default_encoding = true
}
if name == "no_sig_int" {
settings.no_sig_int = true;
}
let value = parts.next().map(ToOwned::to_owned);
(name, value)
}));

View File

@@ -103,7 +103,9 @@ pub(crate) mod _signal {
.clone()
.get_attr("default_int_handler", vm)
.expect("_signal does not have this attr?");
signal(libc::SIGINT, int_handler, vm).expect("Failed to set sigint handler");
if !vm.state.settings.no_sig_int {
signal(libc::SIGINT, int_handler, vm).expect("Failed to set sigint handler");
}
}
#[pyfunction]

View File

@@ -16,6 +16,9 @@ pub struct Settings {
/// -O optimization switch counter
pub optimize: u8,
/// Not set SIGINT handler(i.e. for embedded mode)
pub no_sig_int: bool,
/// -s
pub no_user_site: bool,
@@ -85,6 +88,7 @@ impl Default for Settings {
inspect: false,
interactive: false,
optimize: 0,
no_sig_int: false,
no_user_site: false,
no_site: false,
ignore_environment: false,