def run(self): Connection = None try: # break out with Quit exceptions # Connection loop # Loop back to reset connection while True: try: # break out with Reboot exceptions # Load up configuration from Core.config import Config self.nick = Config.get("Connection", "nick") # Import the Loader # In first run this will do the initial import # Later the import is done by a call to .reboot(), # but we need to import each time to get the new Loader from Core.loader import Loader # System loop # Loop back to reload modules while True: try: # break out with Reload exceptions # Collect any garbage remnants that might have been left behind # from an old loader or backup that wasn't properly dereferenced gc.collect() # Import elements of Core we need # These will have been refreshed by a call to # either Loader.reboot() or Loader.reload() from Core.db import session from Core.connection import Connection from Core.router import Router from Core.robocop import RoboCop # Attach the IRC connection and configure self.irc = Connection.attach(self.irc, self.nick) # Attach the RoboCop/clients sockets and configure self.robocop = RoboCop.attach(*self.robocop) # Operation loop Router.run() except Call999 as exc: # RoboCop server failed, restart it self.robocop = RoboCop.disconnect(str(exc)) continue except Reload: print "%s Reloading..." % (time.asctime(),) # Reimport all the modules Loader.reload() continue except Reboot as exc: # Reset the connection first self.irc = Connection.disconnect(str(exc) or "Rebooting") print "%s Rebooting..." % (time.asctime(),) # Reboot the Loader and reimport all the modules Loader.reboot() continue except (Quit, KeyboardInterrupt, SystemExit) as exc: if Connection is None: sys.exit(exc) Connection.disconnect(str(exc) or "Bye!") sys.exit("Bye!")