-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Correct exitcode when running through subprocess.run
#4454
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
Conversation
I researched about failing in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# TODO: RUSTPYTHON | ||
if sys.platform == "win32": | ||
windows_only_failed_tests = [ | ||
test_pymain_run_file, | ||
test_pymain_run_file_runpy_run_module, | ||
test_pymain_run_file_runpy_run_module_as_main, | ||
test_pymain_run_command_run_module, | ||
test_pymain_run_command, | ||
test_pymain_run_module | ||
] | ||
for t in windows_only_failed_tests: | ||
unittest.expectedFailure(t) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
vm/src/vm/mod.rs
Outdated
unsafe { | ||
if sigaction( | ||
SIGINT, | ||
&SigAction::new( | ||
nix::sys::signal::SigHandler::SigDfl, | ||
SaFlags::SA_ONSTACK, | ||
SigSet::empty(), | ||
), | ||
) | ||
.is_ok() | ||
{ | ||
interpreter::flush_std(self); | ||
kill(getpid(), SIGINT).expect("Expect to be killed."); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a lot of unsafe
.
Does Rust allow, e.g.
if (unsafe { dangerous() }) {
// ...
}
…or is the syntax too restrictive for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know the syntax is available. Only sigaction
function needs unsafe
. So I'll apply it like with cargo fmt
.
unsafe { | |
if sigaction( | |
SIGINT, | |
&SigAction::new( | |
nix::sys::signal::SigHandler::SigDfl, | |
SaFlags::SA_ONSTACK, | |
SigSet::empty(), | |
), | |
) | |
.is_ok() | |
{ | |
interpreter::flush_std(self); | |
kill(getpid(), SIGINT).expect("Expect to be killed."); | |
} | |
} | |
if unsafe { sigaction( | |
SIGINT, | |
&SigAction::new( | |
nix::sys::signal::SigHandler::SigDfl, | |
SaFlags::SA_ONSTACK, | |
SigSet::empty(), | |
), | |
) } | |
.is_ok() | |
{ | |
interpreter::flush_std(self); | |
kill(getpid(), SIGINT).expect("Expect to be killed."); | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can see the change in f4a3049 commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general, you may want to make a new variable for complex expressions.
let action = SigAction::new(
nix::sys::signal::SigHandler::SigDfl,
SaFlags::SA_ONSTACK,
SigSet::empty(),
);
let r = unsafe { sigaction(
SIGINT,
&action,
) };
if r.is_ok() {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied it in a3507e7 commit 🙏🏻
p.s. I'm not sure why review request was removed 🤔
Thank you! |
This pull request fixes exitcode of
SIGINT
(i.e.,KeyboardInterrupt
) when running throughsubprocess.run
.You can run the below script.
CPython
Before (RustPython main)
After (RustPython)
Related links