bpo-42969: Hang non-main threads that attempt to acquire the GIL during finalization by jbms · Pull Request #28525 · python/cpython
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -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
mentioned this pull request
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() | |||