Skip to content

Fix os.closerange and immediate process exit - #9006

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix-portable-os-termination
Oct 8, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix-portable-os-termination

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Split the portable descriptor/termination fixes out of #8954 for the current Python 3.14 main branch.

  • Close raw CRT descriptor numbers in os.closerange, ignoring close errors as required. A range can contain already-closed descriptors and cannot safely be represented by OwnedFd values.
  • Use the host CRT _exit for Python os._exit, failed child exec, the fatal-signal fallback, and faulthandler's exit=True watchdog. Ordinary interpreter shutdown and the non-host fallback are unchanged.

The diff is four Rust files, with no canonical test, workflow, dependency, or profile changes.

Validation

Independently tested on the main-based commit, rather than reusing the mega-PR results:

  • Normal commit hooks and strict workspace/C-API Clippy passed.
  • Workspace tests: 1,352 passed, 18 ignored; separate C-API tests: 116 passed, 4 ignored.
  • C-API-enabled dev and CI production-feature release builds passed, with the Python 3.14 runtime and this checkout's test-source paths verified.
  • Both existing test_os closerange cases, full FileTests, test_atexit, and three canonical child-failure cases passed. Existing platform/implementation skips are unchanged.
  • A child-scoped native C fixture verified that normal exit runs C atexit handlers and flushes buffered C stdio, while os._exit(0/37) and watchdog exit=True do neither. Failed child exec avoids inherited C exit handlers while the parent still cleans up normally. This passed in dev and release builds.

Full local test_os was not run because the sandbox denies its asyncio AF_UNIX socketpair. The unchanged hosted tests remain enabled. Local execution was Linux only; cross-platform CI is pending.

AI assistance

Codex assisted with implementation, extraction, source review, and validation. Both commits retain their Assisted-by disclosure trailers.

Close raw descriptor numbers through the host CRT layer rather than constructing OwnedFd values for possibly closed descriptors. Preserve the half-open range, ignored close errors and Windows invalid-parameter handling.

Assisted-by: Codex:model-version-unavailable
Python os._exit, failed child exec and fatal/watchdog exits must bypass C exit handlers. Call the host CRT _exit on Unix, Windows and WASI while retaining the existing non-host fallback. Normal interpreter termination is unchanged.

Assisted-by: Codex:model-version-unavailable
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40e2aada-881d-477c-a426-0bab0dcd0d13
📥 Commits

Reviewing files that changed from the base of the PR and between bb9ef5d and 1259e5c.

📒 Files selected for processing (4)
  • crates/host_env/src/crt_fd.rs
  • crates/host_env/src/crt_fd_unsupported.rs
  • crates/host_env/src/os.rs
  • crates/vm/src/stdlib/os.rs
 ________________________________________________________________________________________________________________________
< Don't assume it - prove it. Prove your assumptions in the actual environment - with real data and boundary conditions. >
 ------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codspeed

codspeed Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix-portable-os-termination (1259e5c) with main (bb9ef5d)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone marked this pull request as ready for review October 8, 2026 15:12
@youknowone
youknowone merged commit 54e47cd into RustPython:main Oct 8, 2026
30 of 31 checks passed
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