import asyncio from aiofile import AIOFile, Reader, Writer import logging class XMLWriter(): def __init__(self, filename: str): self.filename = filename async def write(self, urls): async with AIOFile(self.filename, 'w') as aiodf: writer = Writer(aiodf) await writer('\n') await writer( '\n') await aiodf.fsync() for url in urls: await writer('{}\n'.format(url)) await aiodf.fsync() await writer('') await aiodf.fsync()