tornado 6.0提供的api下载大文件可以使用如下:import aiofiles
async def get(self):
self.set_header('Content-Type', 'application/octet-stream')
# the aiofiles use thread pool,not real asynchronous
async with aiofiles.open(r"F:\test.xyz","rb") as f:
while True:
data = await f.read(1024)
if not data:
break
self.write(data)
# flush method call is import,it makes low memory occupy,beacuse it send it out timely
self.flush()
只需使用aiofiles,而不使用自冲()可能无法解决问题。在
看看方法自写():
^{pr2}$
在代码:只是将要发送的数据附加到“写入”缓冲区。在
当get或post方法完成并调用finish方法时,将发送数据。在
关于tornado的处理程序flush的文档是: