◐ Shell
clean mode source ↗

Fix EINTR handling by youknowone · Pull Request #7204 · RustPython/RustPython

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Added EINTR-aware retry loops (PEP 475) to VM stdlib write paths and refactored memory view handling in raw_write to use reference-based memory views and properly restore/handle internal borrow buffers across buffered, unbuffered, and non-blocking writes.

Changes

Cohort / File(s) Summary
I/O write paths & memory view handling
crates/vm/src/stdlib/io.rs
Refactored raw_write to construct/reuse memory views via into_ref, handle internal borrowed buffers correctly, and restore internal buffers after writes.
EINTR / signal retry logic
crates/vm/src/stdlib/io.rs
Added EINTR retry loops (PEP 475) using trap_eintr and signal checks across buffered, unbuffered, and non-blocking write flows; preserved EAGAIN behavior for non-blocking writes; updated error propagation to align with retry logic.

Sequence Diagram(s)

sequenceDiagram
    participant VM as VM (raw_write)
    participant Mem as MemoryView / Buffer
    participant OS as OS (write syscall)
    participant Sig as SignalHandler

    VM->>Mem: into_ref / obtain view
    VM->>OS: write(buf)
    OS-->>VM: EINTR
    VM->>Sig: trap_eintr() / check signals
    alt signal handled / retry allowed
        VM->>OS: write(buf)  -- retry loop until success or other error
        OS-->>VM: n_written / EAGAIN / error
    end
    VM->>Mem: restore internal borrow buffer (if used)
    VM-->>Caller: return bytes written or propagate error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

🐰 I nibble bytes with nimble paws,
EINTR met, I pause—then cause
A gentle loop to try once more,
Restore my buffer, steady core,
Bits hop home safe to their doors. 🥕

🚥 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 'Fix EINTR handling' directly and specifically describes the main change in the pull request, which focuses on implementing and fixing EINTR (interrupted system call) handling in write paths.
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 (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 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.