Skip to content

Commit 62766fd

Browse files
authored
Stop non-main threads during interpreter finalization (#7349)
Raise SystemExit in check_signals() for non-main threads once the finalizing flag is set. Without GIL, this serves as the checkpoint where daemon threads detect shutdown, analogous to CPython's _PyThreadState_MustExit in take_gil.
1 parent 9a0511b commit 62766fd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crates/vm/src/vm/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,13 @@ impl VirtualMachine {
14791479
/// Checks for triggered signals and calls the appropriate handlers. A no-op on
14801480
/// platforms where signals are not supported.
14811481
pub fn check_signals(&self) -> PyResult<()> {
1482+
#[cfg(feature = "threading")]
1483+
if self.state.finalizing.load(Ordering::Acquire) && !self.is_main_thread() {
1484+
// once finalization starts,
1485+
// non-main Python threads should stop running bytecode.
1486+
return Err(self.new_exception(self.ctx.exceptions.system_exit.to_owned(), vec![]));
1487+
}
1488+
14821489
#[cfg(not(target_arch = "wasm32"))]
14831490
{
14841491
crate::signal::check_signals(self)

0 commit comments

Comments
 (0)