Does asyncio supports asynchronous I/O for file op

2019-01-18 10:03发布

Does asyncio supports asynchronous I/O for file operations? If yes, how I can use this in Python 3.5 with async/await syntax code?

3条回答
Rolldiameter
2楼-- · 2019-01-18 10:05

That depends what library you use.

curio offers this functionality, https://curio.readthedocs.io/en/latest/reference.html#module-curio.file

plain asyncio doesn't, but there are 3rd party libraries, e.g. https://github.com/Tinche/aiofiles (which is really synchronous file access isolated in threads)

Modern operating systems do provide asynchronous file primitives, but these are varied, thus each would need own implementation. Please compare:

I suspect someone will soon rip out underlying async io from node.js and make a decent Python library, or perhaps someone already has.

查看更多
欢心
3楼-- · 2019-01-18 10:14

asyncio does not have support for this. However, aiofiles supports just this. Please have a look.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-18 10:21

Most operating systems don't support asynchronous file operations. That's why asyncio doesn't support them either.

See the asyncio wiki for further explanation.

查看更多
登录 后发表回答