Add new action queue, synchronized with main thread for prompt like actions (conf loading, exit, ...)
This commit is contained in:
parent
3cfbfd96b0
commit
dda78df9d2
@ -104,8 +104,7 @@ def main():
|
|||||||
# Load requested configuration files
|
# Load requested configuration files
|
||||||
for path in args.files:
|
for path in args.files:
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
from nemubot.tools.config import load_file
|
context.sync_queue.put_nowait(["loadconf", path])
|
||||||
load_file(path, context)
|
|
||||||
else:
|
else:
|
||||||
logger.error("%s is not a readable file", path)
|
logger.error("%s is not a readable file", path)
|
||||||
|
|
||||||
|
@ -125,11 +125,13 @@ class Bot(threading.Thread):
|
|||||||
return res
|
return res
|
||||||
self.hooks.add_hook(nemubot.hooks.Message(_help_msg, "help"), "in", "Command")
|
self.hooks.add_hook(nemubot.hooks.Message(_help_msg, "help"), "in", "Command")
|
||||||
|
|
||||||
# Messages to be treated
|
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
# Messages to be treated
|
||||||
self.cnsr_queue = Queue()
|
self.cnsr_queue = Queue()
|
||||||
self.cnsr_thrd = list()
|
self.cnsr_thrd = list()
|
||||||
self.cnsr_thrd_size = -1
|
self.cnsr_thrd_size = -1
|
||||||
|
# Synchrone actions to be treated by main thread
|
||||||
|
self.sync_queue = Queue()
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -190,6 +192,16 @@ class Bot(threading.Thread):
|
|||||||
self.cnsr_thrd.append(c)
|
self.cnsr_thrd.append(c)
|
||||||
c.start()
|
c.start()
|
||||||
|
|
||||||
|
while self.sync_queue.qsize() > 0:
|
||||||
|
action = self.sync_queue.get_nowait()
|
||||||
|
if action[0] == "exit":
|
||||||
|
self.quit()
|
||||||
|
elif action[0] == "loadconf":
|
||||||
|
for path in action[1:]:
|
||||||
|
from nemubot.tools.config import load_file
|
||||||
|
load_file(path, self)
|
||||||
|
self.sync_queue.task_done()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Events methods
|
# Events methods
|
||||||
|
Loading…
Reference in New Issue
Block a user