Skip to content

fix(rt): prevent GIL from stalling background Rust future tasks#346

Merged
0x676e67 merged 6 commits intomainfrom
rt
Sep 12, 2025
Merged

fix(rt): prevent GIL from stalling background Rust future tasks#346
0x676e67 merged 6 commits intomainfrom
rt

Conversation

@0x676e67
Copy link
Copy Markdown
Owner

@0x676e67 0x676e67 commented Sep 12, 2025

@0x676e67 0x676e67 changed the title fix(rt): prevent GIL from stalling background Rust futures fix(rt): prevent GIL from stalling background Rust future tasks Sep 12, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a custom Rust async runtime to prevent GIL (Global Interpreter Lock) from stalling background Rust future tasks. This addresses PyO3/pyo3-async-runtimes issue #58 by replacing the external pyo3-async-runtimes dependency with an internal runtime implementation.

Key changes:

  • Added custom async runtime module (rt/) with task locals and thread-safe execution
  • Replaced all pyo3_async_runtimes::tokio calls with the new Runtime implementation
  • Added new exception type RustPanic for better error handling

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/rt/mod.rs Core runtime implementation with global Tokio runtime and task-local context management
src/rt/util.rs Utility functions for setting Python future results and thread-safe callbacks
src/rt/task.rs Task management with Python asyncio integration and context variable handling
src/rt/sync.rs Synchronization primitives including cancellable futures and channel senders
src/lib.rs Updated all HTTP method functions to use new Runtime instead of pyo3-async-runtimes
src/client/mod.rs Updated client request methods to use new Runtime
src/client/resp/http.rs Updated response processing to use new Runtime
src/client/resp/ws/mod.rs Updated WebSocket operations to use new Runtime
src/client/resp/stream.rs Updated streaming operations to use new Runtime
src/client/nogil.rs Updated GIL-release functionality to use new Runtime
src/client/body/mod.rs Updated body processing to use new Runtime
src/client/body/multipart.rs Updated multipart form handling to use new Runtime
src/error.rs Added new RustPanic exception type
Cargo.toml Removed pyo3-async-runtimes dependency and added required tokio features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants