diff --git a/cloudbot.py b/cloudbot.py index 60a2aa3..946d413 100644 --- a/cloudbot.py +++ b/cloudbot.py @@ -31,19 +31,19 @@ def exit_gracefully(signum, frame): original_sigint = signal.getsignal(signal.SIGINT) signal.signal(signal.SIGINT, exit_gracefully) -# create new bot object +# create a bot thread and start it cloudbot = bot.Bot() +cloudbot.start() -cloudbot.run() - -# wait for the bot loop to stop - -if cloudbot.do_restart: - # this kills the bot - # TODO: make it not just kill the bot - time.sleep(2) - sys.exit() -else: - print "wtf" - time.sleep(2) - sys.exit() +# watch to see if the bot stops running or needs a restart +while True: + if cloudbot.running: + time.sleep(.1) + else: + if cloudbot.do_restart: + # create a new bot thread and start it + cloudbot = bot.Bot() + cloudbot.start() + continue + else: + break \ No newline at end of file diff --git a/core/bot.py b/core/bot.py index 5c614c6..b963c7c 100644 --- a/core/bot.py +++ b/core/bot.py @@ -4,6 +4,7 @@ import re import os import Queue import collections +import threading from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy import create_engine @@ -45,7 +46,7 @@ def get_logger(): return logger -class Bot(object): +class Bot(threading.Thread): def __init__(self): # basic variables self.start_time = time.time() @@ -71,6 +72,8 @@ class Bot(object): self.loader = PluginLoader(self) + threading.Thread.__init__(self) + def run(self): """recieves input from the IRC engine and processes it"""