aiofiles支持异步文件操作。
举例:
import asyncio
import aiofiles
async def run(text):
async with aiofiles.open('urls.txt', 'a', encoding='utf-8') as f:
await f.write(text)
async def main():
for row in range(0, 100):
print(row)
await run(str(row) + '\n')
asyncio.run(main())
参考:https://github.com/Tinche/aiofiles/