From 67f5bbba4b46bbd84c7531400a1e6c87e1c7f485 Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 13 Jul 2015 16:07:55 -0700 Subject: [PATCH] add a utils.started threaded trigger, so plugins can ACTUALLY wait until all Irc objects have been initialized to do their work --- classes.py | 1 + main.py | 1 + plugins/relay.py | 7 +++++-- utils.py | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/classes.py b/classes.py index 3a035d6..e3d450f 100644 --- a/classes.py +++ b/classes.py @@ -36,6 +36,7 @@ class IrcServer(): self.users = [] self.internal = internal self.name = name.lower() + self.has_bursted = False def __repr__(self): return repr(self.__dict__) diff --git a/main.py b/main.py index 87efa26..4f830ca 100755 --- a/main.py +++ b/main.py @@ -130,5 +130,6 @@ if __name__ == '__main__': sys.exit(2) else: utils.networkobjects[network] = Irc(network, proto, conf.conf) + utils.started.set() log.info("loaded plugins: %s", utils.plugins) diff --git a/plugins/relay.py b/plugins/relay.py index 708c71b..26fe3de 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -295,6 +295,7 @@ def delink(irc, source, args): utils.msg(irc, source, 'Done.') def initializeAll(irc): + utils.started.wait() for chanpair, entrydata in db.items(): network, channel = chanpair initializeChannel(irc, channel) @@ -310,9 +311,10 @@ def main(): thread = threading.Thread(target=scheduler.run) thread.daemon = True thread.start() + ''' for ircobj in utils.networkobjects.values(): initializeAll(irc) - ''' + # Same goes for all the other initialization stuff; we only # want it to happen once. for network, ircobj in utils.networkobjects.items(): @@ -321,5 +323,6 @@ def main(): ''' def handle_endburst(irc, numeric, command, args): - initializeAll(irc) + thread = threading.Thread(target=initializeAll, args=(irc,)) + thread.start() utils.add_hook(handle_endburst, "ENDBURST") diff --git a/utils.py b/utils.py index 4b493cc..39f26ae 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,7 @@ import string import re from collections import defaultdict +import threading from log import log @@ -11,6 +12,7 @@ command_hooks = defaultdict(list) networkobjects = {} schedulers = {} plugins = [] +started = threading.Event() class TS6UIDGenerator(): """TS6 UID Generator module, adapted from InspIRCd source