From 4b50d70dbedf724840daf580a0e902f154ebdd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Mon, 27 Aug 2018 16:07:14 +0200 Subject: [PATCH] Discard past events from reactor queue --- rerunbot.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rerunbot.py b/rerunbot.py index e41407c..acfca0c 100644 --- a/rerunbot.py +++ b/rerunbot.py @@ -117,6 +117,12 @@ class ReplayBot(irc.bot.SingleServerIRCBot): def cb(user=user, msg=msg): return self._post_message(user, msg) self.reactor.scheduler.execute_at(t + offset, cb) + with self.reactor.mutex: + while self.reactor.scheduler.queue: + if self.reactor.scheduler.queue[0].due(): + self.reactor.scheduler.queue.pop(0) + else: + break def _do_resync(self, tags, send_response, offset, **kwargs): if tags['user-id'] not in self.control_users: @@ -129,6 +135,11 @@ class ReplayBot(irc.bot.SingleServerIRCBot): ndc.delay = dc.delay + offset ndc.target = dc.target self.reactor.scheduler.queue[i] = ndc + while self.reactor.scheduler.queue: + if self.reactor.scheduler.queue[0].due(): + self.reactor.scheduler.queue.pop(0) + else: + break def _do_stop(self, tags, send_response, **kwargs): if tags['user-id'] not in self.control_users: