Use .trigger (without triggering read/write threads) to call _check

This commit is contained in:
jesopo 2019-06-06 23:23:46 +01:00
parent 24ca7ed97f
commit 6d44f12193

View file

@ -65,13 +65,14 @@ class Bot(object):
self._wtrigger_client.send(b"TRIGGER") self._wtrigger_client.send(b"TRIGGER")
def trigger(self, def trigger(self,
func: typing.Optional[typing.Callable[[], typing.Any]]=None func: typing.Optional[typing.Callable[[], typing.Any]]=None,
) -> typing.Any: trigger_threads=True) -> typing.Any:
func = func or (lambda: None) func = func or (lambda: None)
if utils.is_main_thread(): if utils.is_main_thread():
returned = func() returned = func()
self._trigger_both() if trigger_threads:
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]
@ -88,7 +89,8 @@ class Bot(object):
type, returned = func_queue.get(block=True) type, returned = func_queue.get(block=True)
self._trigger_both() if trigger_threads:
self._trigger_both()
if type == TriggerResult.Exception: if type == TriggerResult.Exception:
raise returned raise returned
@ -277,12 +279,13 @@ class Bot(object):
def _read_loop(self): def _read_loop(self):
while self.running: while self.running:
print("read loop")
if not self.servers: if not self.servers:
self.running = False self.running = False
self._event_queue.put(lambda: None) self._event_queue.put(lambda: None)
break break
self._event_queue.put(self._check) self.trigger(self._check, False)
events = self._read_poll.poll(self.get_poll_timeout()) events = self._read_poll.poll(self.get_poll_timeout())