def mainloop(): """ function to be used as mainloop. """ while 1: try: time.sleep(1) mainhandler.handle_one() except TLStop: break except KeyboardInterrupt: break except Exception as ex: handle_exception() break globalshutdown()
def runapiserver(port=None, ddir=None): """ start running the API server. needs to be called from the main thread. """ from tl.drivers.tornado.bot import TornadoBot global bot bot = TornadoBot(botname="api-bot") if port: try: port = int(port) except ValueError: pass else: port = 10105 try: server = createserver(ddir or getdatadir()) server.bind(port) logging.warn("starting API server on port %s" % port) server.start() server.io_loop.start() except KeyboardInterrupt: globalshutdown() except Exception as ex: handle_exception() ; os._exit(1) else: globalshutdown()