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 — Implement stop-the-world functionality (for `--disable-gil` builds) · Issue #111964 · python/cpython

Implement stop-the-world functionality (for --disable-gil builds) #111964

New issue
Copy link
New issue
Copy link
Closed
Closed
Implement stop-the-world functionality (for --disable-gil builds)#111964
Copy link
Assignees
colesbury
Labels
3.13only security fixesonly security fixestopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

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

Feature or enhancement

The --disable-gil builds occasionally need to pause all but one thread. Some examples include:

  • Cyclic garbage collection, where this is often called a "stop the world event"
  • Before calling fork(), to ensure a consistent state for internal data structures
  • During interpreter shutdown, to ensure that daemon threads aren't accessing Python objects

In the nogil-3.12 fork, a stop-the-world call paused all threads in all interpreters. In CPython 3.13, we probably want to provide two levels of "stop-the-world": per-interpreter and global. In general, per-interpreter pauses are preferable to global pauses, but there are some cases (like before fork()) where want all threads to pause, so that we don't fork() while a thread is modifying some global runtime structure.

In the default build, stop-the-world calls should generally be no-ops, but global pauses may be useful in a few cases, such as before fork() when using multiple interpreters each with their own "GIL".

In the nogil-3.12 fork, this was implemented together with other GC modifications: colesbury/nogil-3.12@2864b6b36e. I'd like to implement it separately in 3.13 to keep the PRs smaller.

Linked PRs

  • gh-111964: Implement stop-the-world pauses #112471
  • gh-111964: Add _PyRWMutex a "readers-writer" lock #112859
Reacted by Donghee Na
Reacted by Donghee Na

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 10, 2023
  2. Hels15 commented on Nov 21, 2023

    @Hels15
    Hels15
    on Nov 21, 2023
    Contributor
    More actions

    Is someone already working on this? @colesbury

  3. colesbury commented on Nov 21, 2023

    @colesbury
    colesbury
    on Nov 21, 2023
    ContributorAuthor
    More actions

    @Hels15 I've been working on this

  4. corona10
    assigned
    colesbury
    on Nov 21, 2023
  5. colesbury
    added a commit that references this issue on Nov 27, 2023

    pythongh-111964: Implement stop-the-world pauses

    db1dd03
  6. colesbury
    added 2 commits that reference this issue on Dec 7, 2023

    pythongh-111964: Add `_PyRWMutex` a "readers-writer" lock

    fd61525

    pythongh-111964: Implement stop-the-world pauses

    603931c
  7. ericsnowcurrently
    added a commit that references this issue on Dec 16, 2023

    gh-111964: Add _PyRWMutex a "readers-writer" lock (gh-112859)

    5ae75e1
  8. colesbury
    added a commit that references this issue on Dec 18, 2023

    pythongh-111964: Implement stop-the-world pauses

    cf85548
  9. colesbury commented on Jan 3, 2024

    @colesbury
    colesbury
    on Jan 3, 2024
    ContributorAuthor
    More actions

    @markshannon: Carl mentioned you had a question about the stop-the-world implementation and reentrancy. The current implementation in the linked PR does not support reentrancy. Prior implementations in the nogil fork supported reentrancy and behaved like recursive mutexes: only the "outer most" calls stopped or resumed threads; "inner" calls only increment/decrement a counter.

    The only place reentrancy was useful was during runtime finalization (i.e., interpreter shutdown). The stop-the-world mechanism is useful for forcing daemon threads 1 to a consistent state right before we delete their thread states, but we also trigger the GC later during shutdown. Making the stop-the-world calls reentrant was a convenient "hack", but I think there are other ways to achieve the same effect.

    I don't think reentrant stop-the-world calls are generally useful because you are quite restricted on what's safe to call during a stop-the-world pause or you risk deadlock. Other paused threads may be holding the locks you need, so you can't call arbitrary python code or destructors. The GC is (or will be) careful to only call finalizers and weakref callbacks after resuming other threads.

    Footnotes

    1. and potentially non-daemon threads depending on when you press ctrl-c ↩

  10. ericsnowcurrently
    added a commit that references this issue on Jan 23, 2024

    gh-111964: Implement stop-the-world pauses (gh-112471)

    441affc
  11. colesbury
    closed this as completedon Jan 23, 2024
  12. aisk
    added 2 commits that reference this issue on Feb 11, 2024

    pythongh-111964: Add _PyRWMutex a "readers-writer" lock (pythongh-112859

    1101a68

    pythongh-111964: Implement stop-the-world pauses (pythongh-112471)

    7e39f76
  13. Glyphack
    added 2 commits that reference this issue on Sep 2, 2024

    pythongh-111964: Add _PyRWMutex a "readers-writer" lock (pythongh-112859

    09eb4f0

    pythongh-111964: Implement stop-the-world pauses (pythongh-112471)

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

Metadata

Metadata

Assignees

  • @colesbury
    colesbury

Labels

3.13only security fixesonly security fixestopic-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.