async def start(channel):
while True:
m = await client.send_message(channel, "Generating... ")
generator.makeFile()
with open('tmp.png', 'rb') as f:
await client.send_file(channel, f)
await client.delete_message(m)
await asyncio.sleep(2)
我有一个不和谐的机器人,每2秒运行一次任务。我试着用一个无限循环来做这个,但脚本崩溃了Task was destroyed but it is still pending!
我已经阅读了关于asyncio的协同程序,但是我发现没有一个例子使用await
。例如,运行一个协程为await
可以避免这个错误吗?Asyncio,等待和无限循环
'await'在这里不是问题。更多'while True'也是定期调用的常用方式(https://stackoverflow.com/questions/37512182/how-can-i-periodically-execute-a-function-with-asyncio)。显示如何执行该功能,你是否试图停止代码中的任务? – kwarunek