[3.13] gh-120973: Fix thread-safety issues with threading.local (GH-121655) (#122042)

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

This should also fix gh-118490.
(cherry picked from commit e059aa6b01)

Co-authored-by: mpage <mpage@meta.com>
This commit is contained in:
Miss Islington (bot) 2024-07-19 19:49:34 +02:00 committed by GitHub
parent 159ea47ed8
commit bf7f4f357b
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);