Add pre-conditions to avoid on_timeout being called after stop()

Apparently the cancellation request for a TimerHandle doesn't
necessarily have to be honoured despite large periods of time passing
This commit is contained in:
Rapptz 2021-06-06 07:05:17 -04:00
parent 876b1e0f3e
commit 81e9d70b7b

View File

@ -314,7 +314,9 @@ class View:
self._timeout_handler = loop.call_later(self.timeout, self.dispatch_timeout) self._timeout_handler = loop.call_later(self.timeout, self.dispatch_timeout)
def dispatch_timeout(self): def dispatch_timeout(self):
if not self._stopped.done(): if self._stopped.done():
return
self._stopped.set_result(True) self._stopped.set_result(True)
asyncio.create_task(self.on_timeout(), name=f'discord-ui-view-timeout-{self.id}') asyncio.create_task(self.on_timeout(), name=f'discord-ui-view-timeout-{self.id}')