GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Missing critical sections for `PyDict_Next` calls in `_functoolsmodule.c` · Issue #145446 · python/cpython

Missing critical sections for PyDict_Next calls in _functoolsmodule.c #145446

New issue
Copy link
New issue
Copy link
Closed
Closed
Missing critical sections for PyDict_Next calls in _functoolsmodule.c#145446
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@brijkapadia
brijkapadia
opened on Mar 3, 2026
Issue body actions

Bug report

Bug description:

After some discussion on PR #145362, I noticed that in Modules/_functoolsmodule.c, all use cases of PyDict_Next do not use a critical section, which is necessary in for the free-threaded build. The docs say that for PyDict_Next:

The function is not thread-safe in the free-threaded build without external synchronization. You can use Py_BEGIN_CRITICAL_SECTION to lock the dictionary while iterating over it

I have not checked if other files are missing a critical section, but it is definitely possible. I will draft a PR shortly for this issue in the coming days, but if anyone else finds other occurrences of PyDict_Next that are not thread-safe, please let me know.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-145446: Add critical section in functools module for PyDict_Next #145487
  • [3.14] gh-145446: Add critical section in functools module for PyDict_Next (GH-145487) #145879

Activity

  1. brijkapadia
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 3, 2026
  2. aisk commented on Mar 3, 2026

    @aisk
    aisk
    on Mar 3, 2026 · Hidden as outdated
    show commentMore actions
  3. aisk
    added
    topic-free-threading
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 3, 2026
  4. aisk commented on Mar 3, 2026

    @aisk
    aisk
    on Mar 3, 2026 · Hidden as outdated
    show commentMore actions
  5. aisk
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Mar 3, 2026
  6. aisk commented on Mar 3, 2026

    @aisk
    aisk
    on Mar 3, 2026
    Member
    More actions

    Sorry, I re-read your issue, you mean make _functoolsmodule thread-safe when calling PyDict_Next by adding a critical section? The title is a little bit misleading 😂 Updated the title, and please feel free to modify it if I'm wrong.

    Reacted by Brij Kapadia
  7. aisk
    closed this as completedon Mar 3, 2026
  8. aisk
    reopened this on Mar 3, 2026
  9. aisk
    changed the title [-]Make PyDict_Next thread-safe using a critical section[/-] [+]Missing critical sections for `PyDict_Next` calls in `_functoolsmodule.c`[/+] on Mar 3, 2026
  10. aisk
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    and removed
    type-featureA feature request or enhancementA feature request or enhancement
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Mar 3, 2026
  11. brijkapadia commented on Mar 3, 2026

    @brijkapadia
    brijkapadia
    on Mar 3, 2026
    ContributorAuthor
    More actions

    Yes, sorry if I was not clear. I meant to wrap calls to PyDict_Next specifically in _functools_module in a critical section, not to add a critical section inside PyDict_Next. Thank you for changing the title.

  12. encukou
    added a commit that references this issue on Mar 12, 2026

    gh-145446: Add critical section in functools module for `PyDict_Next` (…

    17eb035
  13. brijkapadia
    closed this as completedon Mar 12, 2026
  14. brijkapadia
    added a commit that references this issue on Mar 12, 2026

    [3.14] pythongh-145446: Add critical section in functools module for …

    f44781d
  15. encukou
    added a commit that references this issue on Mar 13, 2026

    [3.14] gh-145446: Add critical section in functools module for `PyDic…

    4856992
  16. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-145446: Add critical section in functools module for `PyDict…

    e2a86e3
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.