Skip to content

Commit 481caf5

Browse files
committed
Allow the wait to be interrupted by CTRL+C.
1 parent 9ccf6bd commit 481caf5

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

Python/pylifecycle.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3488,7 +3488,24 @@ wait_for_native_shutdown(PyInterpreterState *interp)
34883488
}
34893489
PyMutex_Unlock(&finalizing->mutex);
34903490

3491-
PyEvent_Wait(&finalizing->finished);
3491+
PyTime_t wait_ns = 1000 * 1000; // 1 millisecond
3492+
3493+
while (true) {
3494+
if (PyEvent_WaitTimed(&finalizing->finished, wait_ns, 1)) {
3495+
// Event set
3496+
break;
3497+
}
3498+
3499+
if (PyErr_CheckSignals()) {
3500+
// The user CTRL+C'd us, bail out without waiting for a reference
3501+
// count of zero.
3502+
//
3503+
// This will probably cause threads to crash, but maybe that's
3504+
// better than a deadlock. It might be worth intentionally
3505+
// leaking subinterpreters to prevent some crashes here.
3506+
break;
3507+
}
3508+
}
34923509
}
34933510

34943511
int Py_AtExit(void (*func)(void))

0 commit comments

Comments
 (0)