简体   繁体   English

Python Asyncio TimeoutError (tasks.loop)

[英]Python Asyncio TimeoutError (tasks.loop)

I have a script that should run endless.我有一个应该无限运行的脚本。 My problem is that after about 10 minutes a timeout error appears.我的问题是大约 10 分钟后出现超时错误。 I tried a try/except, if it is catched, the start method should be called again.我尝试了一个try/except,如果它被捕获,应该再次调用start方法。 But this does not work.但这不起作用。 The catch work, but the start method cannot be called again. catch 工作,但不能再次调用 start 方法。

Here is my code:这是我的代码:

    @tasks.loop()
    async def beginn(self):
        print(something)
        self.csvToList()
        await self.find_price()

    def start():
        try:
            print("run")
            mon = monitor()
            mon.beginn.start()
            client.run(token)
        except asyncio.TimeoutError:
            print("Timeout")
            start()

    start()

This is the error message这是错误信息

And for the line numbers对于行号

As I see in your code, you wrote client.run(token) .正如我在您的代码中看到的那样,您编写了client.run(token) So maybe this is discord.py.所以也许这是 discord.py。 I think the best solution to this, in order not to end this loop is this:为了不结束这个循环,我认为最好的解决方案是:

@tasks.loop(seconds=1)
async def beginn(self):
    print(something)
    self.csvToList()
    await self.find_price()

@beginn.before_loop
async def before():
    await bot.wait_until_ready()
    print("Finished waiting")



beginn.start()
bot.run(token)

Do not forget to delete YOUR start() function in order this work properly.不要忘记删除您的 start() function 以使其正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM