Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-80050: Update BufferedReader.read docs around non-blocking#130653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
4ed4237
b87870b
2119f78
ec7f023
11b754d
b6d319b
59bd2a1
fbbc382
dea91ab
7c4ef7e
c637402
22bc9aa
1c4a09c
8ea45f3
45bb912
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -528,14 +528,13 @@ I/O Base Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
It inherits from :class:`IOBase`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
The main difference with :class:`RawIOBase` is that methods :meth:`read`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
:meth:`readinto` and :meth:`write` will try (respectively) to read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
as much input as requested or to emit all provided data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
In addition,if the underlying raw stream is in non-blocking mode, when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
system returns would block :meth:`write` will raise :exc:`BlockingIOError` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
with :attr:`BlockingIOError.characters_written` and :meth:`read`will return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
data read so far or``None`` if no data is available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Besides, the :meth:`read` method does not have a default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
implementation that defers to :meth:`readinto`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -568,29 +567,40 @@ I/O Base Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. method:: read(size=-1, /) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Read and return up to *size* bytes. If the argument is omitted, ``None``, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
or negative read as much as possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fewer bytes may be returned than requested. An empty :class:`bytes` object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
is returned if the stream is already at EOF. More than one read may be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
made and calls may be retried if specific errors are encountered, see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
:meth:`os.read`and:pep:`475` for more details. Less than size bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
being returned does not imply that EOF isimminent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
When reading as much as possible the default implementation will use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
``raw.readall`` if available (which should implement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
:meth:`RawIOBase.readall`), otherwise will read in a loop until read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
returns ``None``, an empty :class:`bytes`, or a non-retryable error. For | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
most streams this is to EOF, but for non-blocking streams more data may | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
become available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. note:: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
When the underlying raw stream is non-blocking, implementations may | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
either raise :exc:`BlockingIOError` or return ``None`` if no data is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
available. :mod:`io` implementations return ``None``. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. method:: read1(size=-1, /) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Read and return up to *size* bytes, calling :meth:`~RawIOBase.readinto` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
which may retry if :py:const:`~errno.EINTR` is encountered per | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
:pep:`475`. If *size* is ``-1`` or not provided, the implementation will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
choose an arbitrary value for *size*. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. note:: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
When the underlying raw stream is non-blocking, implementations may | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
either raise :exc:`BlockingIOError` or return ``None`` if no data is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
available. :mod:`io` implementations return ``None``. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. method:: readinto(b, /) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -767,34 +777,21 @@ than raw I/O does. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. method:: peek(size=0, /) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Return bytes from the stream without advancing the position.The number of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
bytes returned may be less or more than requested. If theunderlying raw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
stream is non-blocking and the operation would block, returns empty bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. method:: read(size=-1, /) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
In :class:`BufferedReader` this is the same as :meth:`io.BufferedIOBase.read` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. method:: read1(size=-1, /) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
In :class:`BufferedReader` this is the same as :meth:`io.BufferedIOBase.read1` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. versionchanged:: 3.7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
The *size* argument is now optional. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. class:: BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
A buffered binary stream providing higher-level access to a writeable, non | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -826,8 +823,8 @@ than raw I/O does. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Write the :term:`bytes-like object`, *b*, and return the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
number of bytes written. When in non-blocking mode, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
:exc:`BlockingIOError`with :attr:`BlockingIOError.characters_written` set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
Lines 1918 to 1943 ina7f317d
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
is raised if the buffer needs to be written out butthe raw stream blocks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. class:: BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading.Please reload this page.