Does asyncio supports asynchronous I/O for file operations?

℡╲_俬逩灬. 提交于 2019-11-27 02:38:07

问题


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?


回答1:


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.




回答2:


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:

  • http://man7.org/linux/man-pages/man7/aio.7.html
  • https://msdn.microsoft.com/en-us/library/windows/desktop/aa365683(v=vs.85).aspx
  • https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/TechniquesforReadingandWritingCustomFiles/TechniquesforReadingandWritingCustomFiles.html

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:


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



来源:https://stackoverflow.com/questions/34699948/does-asyncio-supports-asynchronous-i-o-for-file-operations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!