Closed buhman closed 7 years ago
Unfortunately file I/O is different than socket I/O, file descriptors can't really be used with selectors (I think they always report ready, but I'm not really sure what happens on the lowest level). That's why asyncio doesn't support it in the first place. :)
You can Google around for more info.
O_NONBLOCK
Note that this flag has no effect for regular files and block devices; that is, I/O operations will (briefly) block when device activity is required, regardless of whether O_NONBLOCK is set.
:(
I've been comparing how aiofiles does things compared to other libraries like aiohttp.
aiofiles runs blocking functions in threadpools using
loop.run_in_executor
, while aiohttp mostly sets file descriptors to nonblocking mode, then usesloop.add_writer
/loop.add_reader
as necessary.Why did aiofiles choose the former approach?