Skip to content

Commit b6e4471

Browse files
authored
Merge pull request RustPython#4475 from discord9/pr_no_ctrl_c
feat: allow specifying an implementation flag so as to not set SIGINT handler
2 parents e1ab8a9 + 763eaed commit b6e4471

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/settings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) {
245245
if name == "warn_default_encoding" {
246246
warn_default_encoding = true
247247
}
248+
if name == "no_sig_int" {
249+
settings.no_sig_int = true;
250+
}
248251
let value = parts.next().map(ToOwned::to_owned);
249252
(name, value)
250253
}));

vm/src/stdlib/signal.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ pub(crate) mod _signal {
103103
.clone()
104104
.get_attr("default_int_handler", vm)
105105
.expect("_signal does not have this attr?");
106-
signal(libc::SIGINT, int_handler, vm).expect("Failed to set sigint handler");
106+
if !vm.state.settings.no_sig_int {
107+
signal(libc::SIGINT, int_handler, vm).expect("Failed to set sigint handler");
108+
}
107109
}
108110

109111
#[pyfunction]

vm/src/vm/setting.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub struct Settings {
1616
/// -O optimization switch counter
1717
pub optimize: u8,
1818

19+
/// Not set SIGINT handler(i.e. for embedded mode)
20+
pub no_sig_int: bool,
21+
1922
/// -s
2023
pub no_user_site: bool,
2124

@@ -85,6 +88,7 @@ impl Default for Settings {
8588
inspect: false,
8689
interactive: false,
8790
optimize: 0,
91+
no_sig_int: false,
8892
no_user_site: false,
8993
no_site: false,
9094
ignore_environment: false,

0 commit comments

Comments
 (0)