Skip to content

Open the Linux pidfd as a binary FileIO - #3555

Merged
Zac-HD merged 2 commits into
python-trio:mainfrom
Zac-HD:claude/ecstatic-pascal-l7c32r
Oct 23, 2026
Merged

Zac-HD merged 2 commits into
python-trio:mainfrom
Zac-HD:claude/ecstatic-pascal-l7c32r

Conversation

@Zac-HD

@Zac-HD Zac-HD commented Oct 23, 2026

Copy link
Copy Markdown
Member

Process wrapped its pidfd with open(fd), which is text mode with the locale's default encoding. Under -X warn_default_encoding that emits an EncodingWarning every time a process is spawned, which fails test suites that turn warnings into errors. The pidfd is only ever waited on and closed, never read, so wrap it in a plain FileIO instead.

@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (654ba84) to head (3f8bb02).

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3555   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             128          128           
  Lines           19475        19480    +5     
  Branches         1323         1323           
===============================================
+ Hits            19475        19480    +5     
Files with missing lines Coverage Δ
src/trio/_subprocess.py 100.00000% <100.00000%> (ø)
src/trio/_tests/test_subprocess.py 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Zac-HD and others added 2 commits October 23, 2026 01:09
Process wrapped its pidfd with open(fd), which is text mode with the
locale's default encoding. Under -X warn_default_encoding (or
PYTHONWARNDEFAULTENCODING=1) that emits an EncodingWarning every time
a process is spawned, which fails test suites that turn warnings into
errors. The pidfd is only ever waited on and closed, never read, so
wrap it in a plain FileIO instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5JBb9ya4c5gRtm9ug1PyS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5JBb9ya4c5gRtm9ug1PyS
@Zac-HD
Zac-HD force-pushed the claude/ecstatic-pascal-l7c32r branch from e83c17f to 3f8bb02 Compare October 23, 2026 01:09
Comment thread src/trio/_subprocess.py
self._wait_lock: Lock = Lock()

self._pidfd: TextIOWrapper | None = None
self._pidfd: FileIO | None = None

@A5rocks A5rocks Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm actually surprised this explicit type hint is/was necessary. Maybe mypy has improved so it infers this now?

@CoolCat467 CoolCat467 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The test seems a little weird but I guess I can't think of another way to test that. Had to read up on io.FileIO, and yes I think this would be a great use case for it. Though I'm slightly worried about this line:

... members, such as read() and write(), need to have their return values checked explicitly in a retry loop to implement “write all” and “read at least” behavior.

Do we need to worry about that?

@Zac-HD

Zac-HD commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

nope - we never read or write this file descriptor, just wait on it.

@Zac-HD
Zac-HD merged commit b8d658a into python-trio:main Oct 23, 2026
50 checks passed
@Zac-HD
Zac-HD deleted the claude/ecstatic-pascal-l7c32r branch October 23, 2026 01:41
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.

4 participants