You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python 3.8.16 (default, Dec 10 2022, 12:00:00)
[GCC 7.5.0] on localhost
>>>
AIOFile:
Tail-less string
async_open:
0 Hello World
1 Hello World
2 Hello World
3 Hello World
4 Hello World
5 Hello World
6 Hello World
7 Hello World
8 Hello World
9 Hello World
Tail-less string
>>>
So it seems that async_open worked fine while AIOFile context manager lost what was written in the for loop.
The text was updated successfully, but these errors were encountered:
This code works as it should. The fact is that AIOFile is a low-level interface for asynchronous file operations, and the read and write methods accept an offset=0 in bytes at which the operation will be performed.
This allows you to do many independent IO operations on an once opened file without moving the virtual carriage.
For example, you may made 10 concurrent HTTP requests by specifying the Range header, and asynchronously write one opened file, while the offsets must either be calculated manually, or use 10 instances of Writer with specified initial offsets.
In order to provide sequential reading and writing, there is Writer, Reader and LineReader. async_open is not the same as AIOFile, it provides a similar interface for file operations, it simulates methods like read or write as it is implemented in a built-in open.
When
AIOFile
object is used as a context manager then some data is lost. Below is slightly modified example fromREADME.rst
:The output is:
So it seems that
async_open
worked fine whileAIOFile
context manager lost what was written in the for loop.The text was updated successfully, but these errors were encountered: