Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.67k stars 149 forks source link

nonblocking IO #15

Closed buhman closed 7 years ago

buhman commented 7 years ago

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 uses loop.add_writer/loop.add_reader as necessary.

Why did aiofiles choose the former approach?

Tinche commented 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.

buhman commented 7 years ago

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.

:(