def run(self): #this function is called when the bot starts, it does error detection and stuff self.thread_connect.start() self.thread_handle.start() self.thread_detectTimeout.start() #self.thread_consInp.start() while not self.stop: try: if self.breakstuff: self.breakstuff = False raise I_like_trains if self.brokenPipe != False or self.pingTimeout != False: self.echo("Broken Pipe: {}".format(self.brokenPipe), "warn") self.echo("PingTimeout: {}".format(self.pingTimeout), "warn") self.echo("exiting...", "warn") self.exit() self.echo("reconnecting in 10 seconds") time.sleep(4) if self.stop == True: break time.sleep(0.42) except Exception as e: self.echo(traceback.format_exc(), "warn") time.sleep(4) return self.echo("waiting for threads to stop...") for t in threading.enumerate(): try: omitted = False if t.ident == None: omitted = "not started" elif t == threading.main_thread(): omitted = "main thread" elif t == threading.current_thread(): omitted = "current thread" elif t.daemon: omitted = "daemon" if omitted: self.echo("omitted {omitted} thread {thread}".format(thread=t.name, omitted=omitted)) else: self.echo("joining thread {thread}".format(thread=t.name)) t.join(5) if t.is_alive(): self.echo("thread {thread} did not exit within 5 seconds!".format(thread=t.name)) else: self.echo("thread {thread} exited!".format(thread=t.name)) except: self.echo(traceback.format_exc(), "warn") self.echo("all threads stopped!") self.echo("exiting in 2 seconds") time.sleep(2) Echo.end(self.screen) return
import Echo as otherEcho name = sys.argv[1] if len(sys.argv) >=3: joinChansOnStart = str(sys.argv[2]).lower() == "true" else: joinChansOnStart = True restart = True while restart: try: exec(compile(open("IRC.py").read(), "IRC.py", "exec"), globals(), locals()) server = IRCServer( name, joinChansOnStart) server.start() while server.is_alive(): time.sleep(1) restart = server.restart joinChansOnStart = server.joinChansOnStart del server except Exception as e: otherEcho.end() print(traceback.format_exc()) print() if restart:# and not self.end and not self.allowRestart or self.restartOnExc: print("restart in 2 seconds") time.sleep(2) print("restarting now...") else: restart = False print("exiting...") break