move immediate-write-trigger to IRCServer.py, trigger _event_loop for

running=False
This commit is contained in:
jesopo 2019-06-06 17:58:35 +01:00
parent 6f27879d1b
commit f96378ac07
3 changed files with 12 additions and 4 deletions

View file

@ -135,7 +135,6 @@ class Module(ModuleManager.BaseModule):
server.send(utils.irc.protocol.tagmsg(target.name, server.send(utils.irc.protocol.tagmsg(target.name,
{"+draft/typing": "active"}), immediate=True) {"+draft/typing": "active"}), immediate=True)
self.bot.trigger()
module_name = self._get_prefix(hook) or "" module_name = self._get_prefix(hook) or ""
if not module_name and hasattr(hook.function, "__self__"): if not module_name and hasattr(hook.function, "__self__"):

View file

@ -46,8 +46,12 @@ class Bot(object):
self._trigger_functions = [] self._trigger_functions = []
self._events.on("timer.reconnect").hook(self._timed_reconnect) 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") self._rtrigger_client.send(b"TRIGGER")
def trigger_write(self):
self._wtrigger_client.send(b"TRIGGER") self._wtrigger_client.send(b"TRIGGER")
def trigger(self, def trigger(self,
@ -57,7 +61,7 @@ class Bot(object):
if utils.is_main_thread(): if utils.is_main_thread():
returned = func() returned = func()
self._thread_trigger() self._trigger_both()
return returned return returned
func_queue = queue.Queue(1) # type: queue.Queue[str] func_queue = queue.Queue(1) # type: queue.Queue[str]
@ -74,7 +78,7 @@ class Bot(object):
type, returned = func_queue.get(block=True) type, returned = func_queue.get(block=True)
self._thread_trigger() self._trigger_both()
if type == TriggerResult.Exception: if type == TriggerResult.Exception:
raise returned raise returned
@ -262,6 +266,7 @@ class Bot(object):
while self.running: while self.running:
if not self.servers: if not self.servers:
self.running = False self.running = False
self._event_queue.put(lambda: None)
break break
events = self._read_poll.poll(self.get_poll_timeout()) events = self._read_poll.poll(self.get_poll_timeout())

View file

@ -255,6 +255,10 @@ class Server(IRCObject.Object):
line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(), line_obj = IRCLine.SentLine(line_events, datetime.datetime.utcnow(),
self.hostmask(), line_parsed) self.hostmask(), line_parsed)
self.socket.send(line_obj, immediate=immediate) self.socket.send(line_obj, immediate=immediate)
if immediate:
self.bot.trigger_write()
return line_obj return line_obj
def send_raw(self, line: str): def send_raw(self, line: str):
return self.send(utils.irc.parse_line(line)) return self.send(utils.irc.parse_line(line))