Skip to content

Dict watcher API is not thread-safe in free-threaded builds #145235

Closed

Description

@yoney

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


Note: Running test.test_free_threading.test_dict_watcher (added in #145233) emits tsan warnings in the free-threaded tsan build.

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Feb 25, 2026
  2. added 3 commits that reference this issue on May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions