Skip to content

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

Closed
@colesbury

Description

@colesbury

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions