Skip to content

Update asyncio to 3.14.2#6902

Merged
youknowone merged 8 commits intoRustPython:mainfrom
youknowone:asyncio
Feb 1, 2026
Merged

Update asyncio to 3.14.2#6902
youknowone merged 8 commits intoRustPython:mainfrom
youknowone:asyncio

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 30, 2026

Summary by CodeRabbit

  • New Features

    • Introduced remote debugging module enabling introspection of frames, tasks, coroutines, and thread information.
    • Added f_generator attribute to frames for generator-to-frame introspection.
    • Enhanced asyncio fork handling for proper state reset in child processes.
  • Bug Fixes

    • Improved async generator state management and error recovery.
    • Fixed resource cleanup for generators and coroutines on destruction.
    • Enhanced recursive representation protection for asyncio Future and Task objects.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

📝 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.

@youknowone
Copy link
Member Author

follow up #6601

@youknowone youknowone force-pushed the asyncio branch 5 times, most recently from 7735700 to 7ab8d00 Compare February 1, 2026 10:29
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin asyncio

@youknowone youknowone force-pushed the asyncio branch 3 times, most recently from 8794426 to 7b33e16 Compare February 1, 2026 15:18
@github-actions
Copy link
Contributor

github-actions bot commented Feb 1, 2026

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/asyncio
[ ] test: cpython/Lib/test/test_asyncio (TODO: 37)

dependencies:

  • asyncio

dependent tests: (8 tests)

  • asyncio: test_asyncio test_builtin test_contextlib_async test_inspect test_logging test_os test_sys_settrace test_unittest

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@youknowone youknowone marked this pull request as ready for review February 1, 2026 16:55
@youknowone youknowone merged commit d1b55f5 into RustPython:main Feb 1, 2026
14 checks passed
@youknowone youknowone deleted the asyncio branch February 1, 2026 23:04
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