periodic.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:tasky 作者: jreese 项目源码 文件源码
def run_task(self) -> None:
        '''Execute the task inside the asyncio event loop.  Track the time it
        takes to run, and log when it starts/stops.  After `INTERVAL` seconds,
        if/once the task has finished running, run it again until `stop()`
        is called.'''

        while self.running:
            try:
                Log.debug('executing periodic task %s', self.name)
                before = self.time()
                await self.run()
                total = self.time() - before
                Log.debug('finished periodic task %s in %.1f seconds',
                          self.name, total)

                sleep = self.INTERVAL - total
                if sleep > 0:
                    await self.sleep(sleep)

            except CancelledError:
                Log.debug('cancelled periodic task %s', self.name)
                raise

            except Exception:
                Log.exception('exception in periodic task %s', self.name)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号