diff options
| author | 2018-11-27 15:06:10 +0000 | |
|---|---|---|
| committer | 2018-11-27 15:06:10 +0000 | |
| commit | 9d9deb28b58af21ca0b5b1b8881f266eae0efb48 (patch) | |
| tree | c2b9e7fead56f802ba1b9b7d730d02cf129fa64f /src/IRCBot.py | |
| parent | Grab response from functions asked to be executed on the main thread and feed (diff) | |
| signature | ||
Raise exceptions back up through .trigger()
Diffstat (limited to 'src/IRCBot.py')
| -rw-r--r-- | src/IRCBot.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/IRCBot.py b/src/IRCBot.py index d12cc377..1ae8aa54 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -2,6 +2,9 @@ import queue, os, select, socket, sys, threading, time, traceback, typing, uuid from src import EventManager, Exports, IRCServer, Logging, ModuleManager from src import Socket, utils +TRIGGER_RETURN = 1 +TRIGGER_EXCEPTION = 2 + class Bot(object): def __init__(self, directory, args, cache, config, database, events, exports, log, modules, timers): @@ -45,7 +48,11 @@ class Bot(object): self.lock.release() self._trigger_client.send(b"TRIGGER") - return func_queue.get(True) + type, returned = func_queue.get(True) + if type == TRIGGER_EXCEPTION: + raise returned + elif type == TRIGGER_RETURN: + return returned def add_server(self, server_id: int, connect: bool = True, connection_params: typing.Optional[ @@ -177,8 +184,13 @@ class Bot(object): self.cache.expire() for func, func_queue in self._trigger_functions: - returned = func() - func_queue.put(returned) + try: + returned = func() + type = TRIGGER_RETURN + except Exception as e: + returned = e + type = TRIGGER_EXCEPTION + func_queue.put([type, returned]) self._trigger_functions.clear() for fd, event in events: |
