Skip to content

Commit 2e68b15

Browse files
committed
Emit a fatal error for CTRL^Cs while waiting on finalization guards.
1 parent 23a84ab commit 2e68b15

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Python/pylifecycle.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,19 @@ make_pre_finalization_calls(PyThreadState *tstate, int subinterpreters)
23262326
* Again, this is purely an optimization to avoid overloading the CPU.
23272327
*/
23282328
if (_Py_atomic_load_ssize_relaxed(&interp->finalization_guards.countdown) > 0) {
2329-
PyEvent_Wait(&interp->finalization_guards.done);
2329+
for (;;) {
2330+
PyTime_t wait_ns = 1000 * 1000; // 1ms
2331+
if (PyEvent_WaitTimed(&interp->finalization_guards.done, wait_ns, /*detach=*/1)) {
2332+
break;
2333+
}
2334+
2335+
// For debugging purposes, we emit a fatal error if someone
2336+
// CTRL^C'ed the process.
2337+
if (PyErr_CheckSignals()) {
2338+
PyErr_FormatUnraisable("Exception ignored while waiting on finalization guards");
2339+
Py_FatalError("Interrupted while waiting on finalization guard");
2340+
}
2341+
}
23302342
}
23312343

23322344
/* Stop the world to prevent other threads from creating threads or

0 commit comments

Comments
 (0)