Use .trigger (without triggering read/write threads) to call _check
This commit is contained in:
parent
24ca7ed97f
commit
6d44f12193
1 changed files with 8 additions and 5 deletions
|
@ -65,12 +65,13 @@ 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()
|
||||||
|
if trigger_threads:
|
||||||
self._trigger_both()
|
self._trigger_both()
|
||||||
return returned
|
return returned
|
||||||
|
|
||||||
|
@ -88,6 +89,7 @@ class Bot(object):
|
||||||
|
|
||||||
type, returned = func_queue.get(block=True)
|
type, returned = func_queue.get(block=True)
|
||||||
|
|
||||||
|
if trigger_threads:
|
||||||
self._trigger_both()
|
self._trigger_both()
|
||||||
|
|
||||||
if type == TriggerResult.Exception:
|
if type == TriggerResult.Exception:
|
||||||
|
@ -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())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue