From f96378ac07f1ce809c518ac30443d8afd9935063 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 6 Jun 2019 17:58:35 +0100 Subject: [PATCH] move immediate-write-trigger to IRCServer.py, trigger _event_loop for running=False --- modules/commands/__init__.py | 1 - src/IRCBot.py | 11 ++++++++--- src/IRCServer.py | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/commands/__init__.py b/modules/commands/__init__.py index 86fc65a7..436d93cf 100644 --- a/modules/commands/__init__.py +++ b/modules/commands/__init__.py @@ -135,7 +135,6 @@ class Module(ModuleManager.BaseModule): server.send(utils.irc.protocol.tagmsg(target.name, {"+draft/typing": "active"}), immediate=True) - self.bot.trigger() module_name = self._get_prefix(hook) or "" if not module_name and hasattr(hook.function, "__self__"): diff --git a/src/IRCBot.py b/src/IRCBot.py index 3d638fe1..293a76d5 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -46,8 +46,12 @@ class Bot(object): self._trigger_functions = [] self._events.on("timer.reconnect").hook(self._timed_reconnect) - def _thread_trigger(self): + def _trigger_both(self): + self.trigger_read() + self.trigger_write() + def trigger_read(self): self._rtrigger_client.send(b"TRIGGER") + def trigger_write(self): self._wtrigger_client.send(b"TRIGGER") def trigger(self, @@ -57,7 +61,7 @@ class Bot(object): if utils.is_main_thread(): returned = func() - self._thread_trigger() + self._trigger_both() return returned func_queue = queue.Queue(1) # type: queue.Queue[str] @@ -74,7 +78,7 @@ class Bot(object): type, returned = func_queue.get(block=True) - self._thread_trigger() + self._trigger_both() if type == TriggerResult.Exception: raise returned @@ -262,6 +266,7 @@ class Bot(object): while self.running: if not self.servers: self.running = False + self._event_queue.put(lambda: None) break events = self._read_poll.poll(self.get_poll_timeout()) diff --git a/src/IRCServer.py b/src/IRCServer.py index e037eca7..1f2a5b3b 100644 --- a/src/IRCServer.py +++ b/src/IRCServer.py @@ -255,6 +255,10 @@ class Server(IRCObject.Object): line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(), self.hostmask(), line_parsed) self.socket.send(line_obj, immediate=immediate) + + if immediate: + self.bot.trigger_write() + return line_obj def send_raw(self, line: str): return self.send(utils.irc.parse_line(line))