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 — Make queue.SimpleQueue thread-safe in `--disable-gil` builds · Issue #113884 · python/cpython

Make queue.SimpleQueue thread-safe in --disable-gil builds #113884

New issue
Copy link
New issue
Copy link
Closed
Closed
Make queue.SimpleQueue thread-safe in --disable-gil builds#113884
Copy link
Assignees
mpage
Labels
topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@mpage
mpage
opened on Jan 9, 2024
Issue body actions

Feature or enhancement

Proposal:

Instances of queue.SimpleQueue have mutable state that is not safe to mutate without the GIL. The previous implementation (in 3.12) was colesbury/nogil-3.12@7e60a01aee.

@colesbury - You mentioned in chat that porting the 3.12 approach wouldn't be straightforward. Can you say more?

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-113884: Make queue.SimpleQueue thread-safe in --disable-gil builds #114161
  • gh-113884: Refactor queue.SimpleQueue to use a ring buffer to store items #114259

Activity

  1. mpage
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jan 9, 2024
  2. AlexWaygood
    added
    topic-free-threading
    on Jan 9, 2024
  3. colesbury commented on Jan 9, 2024

    @colesbury
    colesbury
    on Jan 9, 2024
    Contributor
    More actions

    @mpage, after looking it over again, I think the nogil-3.12 approach is mostly the right direction with a few modifications:

    1. Replace the manual _PyMutex_lock()/unlock() calls with critical sections and remove the _PyMutex mutex field. Since, the code already uses Argument Clinic (AC), this is mostly just a matter of adding the @critical_section to the AC input. This will avoid the extra lock operations in the default build, which can rely on the GIL.
    2. The parking lot API changed slightly; it's not a huge difference. For example, the unpark operation now takes a callback

    This means we will go from a SimpleQueue implementation built around list to run that more explicitly manages a buffer. I think that's worthwhile here; otherwise I think handling the synchronization across both the list operations and the containing SimpleQueue will be too messy.

    Reacted by mpage
  4. colesbury
    assigned
    mpage
    on Jan 9, 2024
  5. erlend-aasland
    added a commit that references this issue on Jan 19, 2024

    gh-113884: Refactor `queue.SimpleQueue` to use a ring buffer to store…

    28eacf2
  6. kulikjak
    added a commit that references this issue on Jan 22, 2024

    pythongh-113884: Refactor `queue.SimpleQueue` to use a ring buffer to…

    208f0a7
  7. erlend-aasland
    added a commit that references this issue on Jan 23, 2024

    gh-113884: Make queue.SimpleQueue thread-safe when the GIL is disabled (

    925907e
  8. erlend-aasland commented on Jan 23, 2024

    @erlend-aasland
    erlend-aasland
    on Jan 23, 2024
    Contributor
    More actions

    Thank you, @mpage and @colesbury 🙏

  9. erlend-aasland
    closed this as completedon Jan 23, 2024
  10. aisk
    added 2 commits that reference this issue on Feb 11, 2024

    pythongh-113884: Refactor `queue.SimpleQueue` to use a ring buffer to…

    fd8141d

    pythongh-113884: Make queue.SimpleQueue thread-safe when the GIL is d…

    1b9b471
  11. Glyphack
    added 2 commits that reference this issue on Sep 2, 2024

    pythongh-113884: Refactor `queue.SimpleQueue` to use a ring buffer to…

    25a152f

    pythongh-113884: Make queue.SimpleQueue thread-safe when the GIL is d…

    2adfdfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mpage
    mpage

Labels

topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

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.