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 — clear_after_fork by youknowone · Pull Request #6933 · RustPython/RustPython

Conversation

@youknowone

@youknowone youknowone commented Feb 1, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved process fork behavior to properly reset signal state and internal synchronization mechanisms in child processes, preventing stale parent state from affecting child process execution.

✏️ Tip: You can customize this high-level summary in your review settings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@youknowone
clear_after_fork
e58b7b3
@coderabbitai

coderabbitai Bot commented Feb 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds post-fork cleanup routines for signal state, wakeup file descriptors, and weakref locks. These functions reset inherited parent state in child processes before Python code execution, preventing stale parent signals and locks from interfering with child process behavior.

Changes

Cohort / File(s) Summary
Signal state cleanup
crates/vm/src/signal.rs, crates/vm/src/stdlib/signal.rs
Added UNIX-only functions to reset global signal state (clear_after_fork()) and wakeup fd state (clear_wakeup_fd_after_fork()) after fork operations.
Weakref lock cleanup
crates/vm/src/object/core.rs
Added UNIX-only functions to reset weakref stripe locks (reset_all_after_fork()) and a public wrapper (reset_weakref_locks_after_fork()) guarded by threading configuration.
Post-fork orchestration
crates/vm/src/stdlib/posix.rs
Integrated cleanup calls into py_os_after_fork_child() to invoke signal, wakeup fd, and weakref lock resets before Python code runs in child process.

Sequence Diagram

sequenceDiagram
    participant Fork Process
    participant Child Init as py_os_after_fork_child()
    participant Signal Module
    participant Signal FD Module
    participant Weakref Module

    Fork Process->>Child Init: fork() → child process starts
    Child Init->>Signal Module: clear_after_fork()
    Signal Module->>Signal Module: reset ANY_TRIGGERED & TRIGGERS
    Signal Module-->>Child Init: ✓ signal state cleared
    Child Init->>Signal FD Module: clear_wakeup_fd_after_fork()
    Signal FD Module->>Signal FD Module: reset WAKEUP to INVALID_WAKEUP
    Signal FD Module-->>Child Init: ✓ wakeup fd cleared
    Child Init->>Weakref Module: reset_weakref_locks_after_fork()
    Weakref Module->>Weakref Module: reset all stripe locks
    Weakref Module-->>Child Init: ✓ weakref locks cleared
    Child Init->>Child Init: run after_fork_child(vm)
    Child Init-->>Fork Process: child initialized & ready
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • impl preexec_fn #6479: Modifies child-after-fork execution path and VM handling during fork operations.
  • various fix to support subprocess/multiprocessing #6567: Adds RLock recursion reset to child-after-fork reinitialization, complementing this PR's other state resets.

Poem

🐰 A fork in the road, the process did split,
Locks and signals left in a bit of a fit!
Reset, reset, the rabbit did say,
Clear state before Python runs its way! 🔄

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'clear_after_fork' directly matches the primary objective of the changes: adding fork-safe cleanup functions to reset global state (signals, weakref locks, wakeup FDs) after process forking.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands and usage tips.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone marked this pull request as ready for review February 1, 2026 10:01
@youknowone
youknowone enabled auto-merge (squash) February 1, 2026 10:15
@youknowone
youknowone disabled auto-merge February 1, 2026 10:42
@youknowone
youknowone merged commit dd09f41 into RustPython:main Feb 1, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone deleted the clear-after-fork branch February 1, 2026 10:42
@coderabbitai coderabbitai Bot mentioned this pull request Feb 9, 2026
Fix signal handler after fork #7012
Merged
This was referenced Feb 17, 2026
Use try_lock in py_os_after_fork_child #7178
Merged
force_unlock_after_fork #7186
Merged
Fix deadlock after fork #7205
Merged
@coderabbitai coderabbitai Bot mentioned this pull request Mar 3, 2026
Add monitoring lock reinit and use raw() accessor #7335
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@youknowone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.