◐ Shell
clean mode source ↗

Update asyncio to 3.14.2 by youknowone · Pull Request #6902 · RustPython/RustPython

📝 Walkthrough

Walkthrough

Implements frame-generator bidirectional references via PyAtomicBorrow to break reference cycles, adds Drop implementations for cleanup, enhances asyncio with fork handling and guarded representations, introduces _remote_debugging module, and exposes frame generator introspection.

Changes

Cohort / File(s) Summary
Asyncio Fork Handling & Repr Guarding
crates/stdlib/src/_asyncio.rs
Added Unix-only _on_fork function to reset per-thread task state and module-level _current_tasks dict; introduced ReprGuard protection for recursive Future/Task reprs; added qualname getters to TaskStepMethWrapper, TaskWakeupMethWrapper, and PyTask; enhanced per-thread task tracking and cross-thread awaited_by introspection.
Remote Debugging Module
crates/stdlib/src/_remote_debugging.rs, crates/stdlib/src/lib.rs
Introduced new _remote_debugging module with struct sequences (FrameInfo, TaskInfo, CoroInfo, ThreadInfo, AwaitedInfo) and RemoteUnwinder placeholder class; integrated module into stdlib initialization pipeline.
Frame-Generator Bidirectional References
crates/vm/src/object/ext.rs, crates/vm/src/frame.rs
Added PyAtomicBorrow non-owning atomic reference type to break generator↔frame cycles; implemented set_generator/clear_generator methods on Frame; introduced f_generator getter; refactored yield_from_target to use try_lock-based local execution path.
Generator & Coroutine Lifecycle
crates/vm/src/builtins/generator.rs, crates/vm/src/builtins/coroutine.rs, crates/vm/src/builtins/function.rs
Added Drop implementations for PyGenerator and PyCoroutine to clear frames; updated invoke_with_locals to register created generators on frames via set_generator.
Async Generator State Management
crates/vm/src/builtins/asyncgenerator.rs
Refined state machine transitions for await operations; replaced close() with set_closed() in error paths to avoid full close semantics; extended close methods to accept VirtualMachine; added Drop implementation for frame cleanup; improved error message formatting.

Sequence Diagram(s)

sequenceDiagram
    participant Module as Module Init
    participant ForkHook as Fork Hook Registry
    participant Parent as Parent Process
    participant Fork as Fork System Call
    participant Child as Child Process
    participant OnFork as _on_fork Handler
    participant State as Asyncio State

    Module->>ForkHook: Register _on_fork (Unix only)
    Parent->>Fork: fork()
    Fork->>Parent: Continue with child PID
    Fork->>Child: New process created
    Child->>OnFork: Invoke registered hook
    OnFork->>State: Clear per-thread running loop
    OnFork->>State: Clear per-thread running task
    OnFork->>State: Reset _current_tasks dict
    State-->>Child: Clean asyncio state
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~65 minutes

Possibly related PRs

Suggested reviewers

  • ShaharNaveh
  • fanninpm
  • coolreader18

Poem

🐰 The frames and generators dance in pairs,
Yet cycles threaten their affair—
A borrowed reference breaks the knot,
While forks reset what should be forgot.
In Drop we trust, and state's cleaned bright,
The rabbit's work makes asyncio right! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Update asyncio to 3.14.2' is vague and generic. While it mentions version 3.14.2, the changeset includes substantial additions beyond a simple dependency update: new remote debugging infrastructure, frame-to-generator linking via PyAtomicBorrow, async generator lifecycle fixes, and comprehensive asyncio task/fork management. Clarify the title to reflect the main technical changes, such as 'Add frame-to-generator linking and remote debugging scaffolding' or 'Refactor asyncio task lifecycle and generator frame management'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.