Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Feb 1, 2026

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

📝 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

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

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

@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
@youknowone youknowone deleted the clear-after-fork branch February 1, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant