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 `random.Random` thread-safe in `--disable-gil` builds · Issue #112071 · python/cpython

Make random.Random thread-safe in --disable-gil builds #112071

New issue
Copy link
New issue
Copy link
Closed
#112128
Closed
Make random.Random thread-safe in --disable-gil builds#112071
#112128
Copy link
Assignees
chgnrdv
Labels
3.13only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Nov 14, 2023
Issue body actions

Feature or enhancement

random.Random has mutable internal state. We should use the critical section API to make it thread-safe in --disable-gil builds.

For context, here is the change from the nogil-3.12 fork. colesbury/nogil-3.12@9bf62ffc4b. Note that we want to do things a bit differently in CPython 3.13:

  1. No need for an extra _PyMutex mutex in RandomObject
  2. Use the critical section API. Locking can be added around operations that use Argument Clinic by adding the @critical_section directive as the first line.
  3. Compared to nogil-3.12, we want to push the locking "up" to the around the methods. (See the above note 2).

Linked PRs

  • gh-112071: Make _random.Random methods thread-safe in --disable-gil builds #112128

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.13only security fixesonly security fixes
    topic-free-threading
    on Nov 14, 2023
  2. AlexWaygood
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Nov 14, 2023
  3. chgnrdv commented on Nov 15, 2023

    @chgnrdv
    chgnrdv
    on Nov 15, 2023
    Contributor
    More actions

    The PR is done.

  4. colesbury
    assigned
    colesbury
    and
    chgnrdv
    and unassigned
    colesbury
    on Nov 15, 2023
  5. corona10
    closed this as completedin #112128on Nov 28, 2023
  6. corona10
    added a commit that references this issue on Nov 28, 2023

    gh-112071: Make `_random.Random` methods thread-safe in `--disable-gi…

    ac4b442
  7. aisk
    added a commit that references this issue on Feb 11, 2024

    pythongh-112071: Make `_random.Random` methods thread-safe in `--disa…

    8e17880
  8. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythongh-112071: Make `_random.Random` methods thread-safe in `--disa…

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

Metadata

Metadata

Assignees

  • @chgnrdv
    chgnrdv

Labels

3.13only security fixesonly security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-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.