Add new action queue, synchronized with main thread for prompt like actions (conf loading, exit, ...)

This commit is contained in:
nemunaire 2015-05-07 06:39:34 +02:00
parent 3cfbfd96b0
commit dda78df9d2
2 changed files with 14 additions and 3 deletions

View File

@ -104,8 +104,7 @@ def main():
# Load requested configuration files
for path in args.files:
if os.path.isfile(path):
from nemubot.tools.config import load_file
load_file(path, context)
context.sync_queue.put_nowait(["loadconf", path])
else:
logger.error("%s is not a readable file", path)

View File

@ -125,11 +125,13 @@ class Bot(threading.Thread):
return res
self.hooks.add_hook(nemubot.hooks.Message(_help_msg, "help"), "in", "Command")
# Messages to be treated
from queue import Queue
# Messages to be treated
self.cnsr_queue = Queue()
self.cnsr_thrd = list()
self.cnsr_thrd_size = -1
# Synchrone actions to be treated by main thread
self.sync_queue = Queue()
def run(self):
@ -190,6 +192,16 @@ class Bot(threading.Thread):
self.cnsr_thrd.append(c)
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