【问题标题】:Python Asyncio TimeoutError (tasks.loop)Python Asyncio TimeoutError (tasks.loop)
【发布时间】:2021-04-13 09:48:03
【问题描述】:

我有一个可以无限运行的脚本。我的问题是大约 10 分钟后出现超时错误。 我尝试了一个try/except,如果它被捕获,应该再次调用start方法。但这不起作用。 catch 工作了,但是 start 方法不能再调用了。

这是我的代码:

    @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

【问题讨论】:

    标签: python timeout infinite-loop


    【解决方案1】:

    正如我在你的代码中看到的,你写了client.run(token)。所以也许这是 discord.py。 为了不结束这个循环,我认为最好的解决方案是:

    @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)
    

    不要忘记删除 YOUR start() 函数以使其正常工作。

    【讨论】:

      猜你喜欢
      • 2022-12-18
      • 2020-09-23
      • 2021-01-28
      • 1970-01-01
      • 2018-02-10
      • 1970-01-01
      • 2018-10-22
      • 2022-01-16
      • 1970-01-01
      相关资源
      最近更新 更多