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 — Use stop-the-world to make fork and interpreter shutdown thread-safe · Issue #116522 · python/cpython

Use stop-the-world to make fork and interpreter shutdown thread-safe #116522

New issue
Copy link
New issue
Copy link
Closed
Closed
Use stop-the-world to make fork and interpreter shutdown thread-safe#116522
Copy link
Assignees
colesbury
Labels
topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Mar 8, 2024
Issue body actions

Feature or enhancement

In the free-threaded build, we should use a stop-the-world call to make fork() 1 and shutdown (i.e, Py_FinalizeEx) thread-safe.

The two operations are similar in that they both involve deleting thread states for other threads.

Fork

Fork and in multithreaded environments is notorious for the problems it causes, but we can make the free-threaded build at least as safe as the default (GIL) build by pausing other threads with a stop-the-world call before forking. In the parent, we can use a normal start-the-world call to resume other threads after fork. In the child, we want to call start the world after other thread states are removed, but before we execute python code. This may require some refactoring.

Shutdown

The interpreter waits for threading module created non-daemon threads during shutdown, but this can be canceled by a ctrl-c and there may still be active thread states for daemon threads and threads created from C outside of the threading module. We should use a stop-the-world call to bring these threads to a consistent state before we try deleting their thread states.

Linked PRs

  • gh-116522: Stop the world before fork() and during shutdown #116607
  • gh-116522: Refactor _PyThreadState_DeleteExcept #117131

Footnotes

  1. or at least less thread-unsafe... ↩

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-free-threading
    on Mar 8, 2024
  2. Rajendra1308 commented on Mar 9, 2024

    @Rajendra1308
    Rajendra1308
    on Mar 9, 2024
    More actions

    Hey @colesbury I would like to work on this, can I get more info. And what file to modify. I am a beginner to this repo, please help.

  3. colesbury commented on Mar 9, 2024

    @colesbury
    colesbury
    on Mar 9, 2024
    ContributorAuthor
    More actions

    Hi @Rajendra1308, thanks for your interest but I'm already working on this.

  4. colesbury
    self-assigned this
    on Mar 9, 2024
  5. Rajendra1308 commented on Mar 10, 2024

    @Rajendra1308
    Rajendra1308
    on Mar 10, 2024
    More actions

    Hey @colesbury , alright. Good Luck!

  6. colesbury
    added 9 commits that reference this issue on Mar 11, 2024

    pythongh-116522: Stop the world before fork() and during shutdown

    2f1ad20

    pythongh-116522: Stop the world before fork() and during shutdown

    c2ebedb

    Merge branch 'pythongh-116522-fork-shutdown' into nogil-integration

    bcb3865

    Merge branch 'pythongh-116522-fork-shutdown' into nogil-integration

    b2c915c

    Merge branch 'pythongh-116522-fork-shutdown' into nogil-integration

    fda5574

    Merge branch 'pythongh-116522-fork-shutdown' into nogil-integration

    82cf216

    Merge branch 'pythongh-116522-fork-shutdown' into nogil-integration

    9552433

    gh-116522: Stop the world before fork() and during shutdown (#116607)

    e728303

    pythongh-116522: Refactor `_PyThreadState_DeleteExcept`

    8c25c8f
  7. gpshead
    added a commit that references this issue on Mar 21, 2024

    gh-116522: Refactor `_PyThreadState_DeleteExcept` (#117131)

    1f72fb5
  8. adorilson
    added 2 commits that reference this issue on Mar 25, 2024

    pythongh-116522: Stop the world before fork() and during shutdown (py…

    6d0cefb

    pythongh-116522: Refactor `_PyThreadState_DeleteExcept` (python#117131)

    f6ef852
  9. colesbury
    closed this as completedon Mar 27, 2024
  10. NGRsoftlab
    added 2 commits that reference this issue on Apr 2, 2024

    Squashed commit of the following:

    1b5fe4c

    Squashed commit of the following:

    a016a54
  11. diegorusso
    added 2 commits that reference this issue on Apr 17, 2024

    pythongh-116522: Stop the world before fork() and during shutdown (py…

    26fa43f

    pythongh-116522: Refactor `_PyThreadState_DeleteExcept` (python#117131)

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

Metadata

Metadata

Assignees

  • @colesbury
    colesbury

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.