bpo-42969: Hang non-main threads that attempt to acquire the GIL during finalization by jbms · Pull Request #28525 · python/cpython

Conversation

{
dprintf(("PyThread_pause_thread called\n"));
while (1) {
pause();
while (1) {
GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@@ -306,4 +306,44 @@ PyCOND_BROADCAST(PyCOND_T *cv)

#endif /* _POSIX_THREADS, NT_THREADS */

/* Convenience interfaces that terminate the program in case of an error. */
#define MUTEX_INIT(mut) \
@@ -1615,6 +1616,47 @@ PyGILState_Release(PyGILState_STATE oldstate)
PyEval_SaveThread();
}

int
PyThread_TryAcquireFinalizeBlock()
{
dprintf(("PyThread_pause_thread called\n"));
while (1) {
pause();
while (1) {
if (GetMessage(&msg, NULL, 0, 0) == -1) return;
TranslateMessage(&msg);
DispatchMessage(&msg);
`PyGILState_ReleaseGilAndFinalizeBlock` with the same value returned by this
function. Calling `PyGILState_ReleaseGilAndFinalizeBlock` with the error
value `PyGILState_TRY_LOCK_FAILED` is safe and does nothing. */
PyAPI_FUNC(PyGILState_TRY_STATE) PyGILState_TryAcquireFinalizeBlockAndGil();

@jbms jbms mentioned this pull request

Sep 24, 2021

3 tasks

{
dprintf(("PyThread_pause_thread called\n"));
while (1) {
pause();
@@ -1615,6 +1616,47 @@ PyGILState_Release(PyGILState_STATE oldstate)
PyEval_SaveThread();
}

int
PyThread_TryAcquireFinalizeBlock()
while (1) {
Sleep(INFINITE);
}