gh-120973: Fix thread-safety issues with threading.local (#121655)

This is a small refactoring to the current design that allows us to
avoid manually iterating over threads.

This should also fix gh-118490.
This commit is contained in:
mpage 2024-07-19 10:22:02 -07:00 committed by GitHub
parent 2009e25e26
commit e059aa6b01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 245 additions and 150 deletions

View file

@ -1702,6 +1702,9 @@ PyThreadState_Clear(PyThreadState *tstate)
/* Don't clear tstate->pyframe: it is a borrowed reference */
Py_CLEAR(tstate->threading_local_key);
Py_CLEAR(tstate->threading_local_sentinel);
Py_CLEAR(((_PyThreadStateImpl *)tstate)->asyncio_running_loop);
Py_CLEAR(tstate->dict);