小编use*_*289的帖子

Asyncio,等待和无限循环

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)
Run Code Online (Sandbox Code Playgroud)

我有一个discord bot,每2秒运行一次任务.我尝试使用无限循环,但是脚本崩溃了,Task was destroyed but it is still pending!我已经阅读了有关asyncio的协同程序的内容,但是我发现await它们都没有使用.await例如,通过运行协同程序可以避免此错误吗?

infinite-loop python-3.x python-asyncio discord.py

5
推荐指数
1
解决办法
5053
查看次数