Skip to content

prototype: _pyio.Nibbler through BufferedWriter (v1) - #2

Draft
cmaloney wants to merge 2 commits into
mainfrom
exp/pyio_nibbler_v1
Draft

cmaloney wants to merge 2 commits into
mainfrom
exp/pyio_nibbler_v1

Conversation

@cmaloney

Copy link
Copy Markdown
Owner

One of the forms I built of this. Focuses on BufferedWriter. Iterating with AI / not all comments as clean as I might like and definitely more refactoring to do.

cmaloney and others added 2 commits May 14, 2026 14:23
Replaces BufferedWriter's bytearray + _write_lock with a _Nibbler buffer
manager built around _Morsel work units. Adds FileIO._writev so the
nibbler can issue a single writev(2) for multi-buffer flushes when
available, falling back to coalesce+write otherwise.

The Nibbler holds its lock end-to-end across raw I/O, matching the
pre-existing cross-thread write ordering guarantee. A future two-lock
split (short buffer lock + I/O lock) is sketched in the class docstring
as the intended path for releasing the I/O lock once profiling justifies
it.

Also restores f.close() in BufferSizeTest.try_one's nested finally and
skips test_slow_close_from_thread pending a way to validate pythongh-76157 /
pythongh-31976 that does not assume the old lock-across-I/O behavior.

See: https://discuss.python.org/t/reworking-buffered-i-o-in-cpython/90019

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cmaloney cmaloney changed the title Exp/pyio nibbler v1 Exp/pyio nibbler BufferedWriter v1 May 14, 2026
@cmaloney cmaloney changed the title Exp/pyio nibbler BufferedWriter v1 prototype: _pyio.Nibbler throu BufferedWriter (v1) May 15, 2026
@cmaloney cmaloney changed the title prototype: _pyio.Nibbler throu BufferedWriter (v1) prototype: _pyio.Nibbler through BufferedWriter (v1) May 15, 2026
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.

1 participant