def dispatch_timers(self):
try:
while not self.bot.is_closed():
# can only asyncio.sleep for up to ~48 days reliably
# so we're gonna cap it off at 40 days
# see: http://bugs.python.org/issue20493
timers = await self.wait_for_active_timers(days=40)
timer = self._current_timer = timers[0]
now = datetime.datetime.utcnow()
if timer.expires >= now:
to_sleep = (timer.expires - now).total_seconds()
await asyncio.sleep(to_sleep)
await self.call_timer(timer)
except asyncio.CancelledError:
pass
except (OSError, discord.ConnectionClosed, asyncpg.PostgresConnectionError):
self._task.cancel()
self._task = self.bot.loop.create_task(self.dispatch_timers())
评论列表
文章目录