Bug report
Bug description:
PyDict_AddWatcher, PyDict_ClearWatcher, PyDict_Watch, PyDict_Unwatch, and _PyDict_SendEvent are not safe to call concurrently in free-threaded builds. The shared callback array and per-dict _ma_watcher_tag can race when watchers are registered, removed, or triggered from multiple threads.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-145235: Make dict watcher API thread-safe for free-threaded builds #145233
- [3.15] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233) #149690
- [3.14] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233) #149691
Note: Running test.test_free_threading.test_dict_watcher (added in #145233) emits tsan warnings in the free-threaded tsan build.