impl more winapi by youknowone · Pull Request #6529 · RustPython/RustPython
📝 Walkthrough
Walkthrough
Six new Windows API Python-callable wrappers were added to the stdlib module: named pipe utilities (WaitNamedPipe, PeekNamedPipe), event management (CreateEventW, SetEvent), file I/O (WriteFile), and a sophisticated BatchedWaitForMultipleObjects function that batches handle waiting, manages thread coordination, and handles timeouts across multiple handle groups.
Changes
| Cohort / File(s) | Summary |
|---|---|
Named Pipe Utilities crates/vm/src/stdlib/winapi.rs |
Added WaitNamedPipe() to wait for pipe availability with timeout and PeekNamedPipe() to query pipe status and read peek data without consuming it. |
Event Management crates/vm/src/stdlib/winapi.rs |
Added CreateEventW() to create manual or automatic reset event objects with optional naming, and SetEvent() to signal event state. |
File I/O Operations crates/vm/src/stdlib/winapi.rs |
Added WriteFile() wrapper supporting buffer writing with optional overlapped I/O flag, returning bytes written and error code. |
Multi-Handle Waiting crates/vm/src/stdlib/winapi.rs |
Implemented BatchedWaitForMultipleObjects() with complex control flow: batches handles (max 64 per batch), supports wait_all/wait_any modes, manages timeouts via cancel events, spawns coordinating threads, and collects triggered handle indices. |
Comment Refinement crates/vm/src/stdlib/winapi.rs |
Minor wording adjustment in LCMapStringEx rejection comment; behavior unchanged. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant BatchedWait as BatchedWaitForMultipleObjects
participant Batcher as Batching Logic
participant Thread as Worker Threads
participant WinAPI as Windows API
participant Events as Event Objects
Client->>BatchedWait: call with handles, wait_all, timeout
BatchedWait->>Events: create cancel_event
rect rgb(220, 240, 255)
note over BatchedWait,Batcher: Batching Phase
BatchedWait->>Batcher: partition handles into groups (≤64 each)
end
rect rgb(240, 220, 255)
note over Thread,WinAPI: Parallel Waiting Phase
par Per-Batch Processing
Batcher->>Thread: spawn worker thread for batch
Thread->>WinAPI: WaitForMultipleObjects(batch + cancel_event)
WinAPI-->>Thread: returns triggered index or timeout
Thread->>Thread: collect result & triggered indices
end
end
rect rgb(240, 255, 220)
note over BatchedWait,Thread: Coordination & Cleanup
alt timeout elapsed
BatchedWait->>Events: signal cancel_event
Thread->>Thread: abort wait, cleanup
end
BatchedWait->>BatchedWait: collect all thread results
BatchedWait->>BatchedWait: build return (status + indices)
end
BatchedWait-->>Client: return PyObjectRef (result tuple)
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- nt.skiproot, winapi.LCMapStringEx #6399: Modifies the same file (crates/vm/src/stdlib/winapi.rs) with overlapping implementation of LCMapStringEx, which this PR adjusts with a comment refinement.
Suggested reviewers
- ShaharNaveh
Poem
🐰 Whiskers twitching with delight,
New event loops shimmer bright!
Batched handles dance in sync,
Threading threads in coordinated link,
Windows API dreams come alive tonight!
Pre-merge checks and finishing touches
❌ Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | ❓ Inconclusive | The title 'impl more winapi' is overly vague and does not clearly convey the specific changes being made. | Use a more descriptive title that specifies which Windows API functions are being added, such as 'Add Windows event and named pipe functions to stdlib' |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ 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.
Comment @coderabbitai help to get the list of available commands and usage tips.