def main(): tornado.options.parse_command_line() settings = initialize_settings() application = make_application(settings) httpserver = HTTPServer(application, xheaders=True) # signal handler def sig_handler(sig, frame): logging.warn("Caught Signal: %s" % sig) tornado.ioloop.IOLoop.instance().add_callback(shutdown) # signal handler's callback def shutdown(): logging.info("Stopping HttpServer ...") httpserver.stop() # No longer accept new http traffic instance = tornado.ioloop.IOLoop.instance() deadline = time.time() + settings['sigint_timeout'] # recursion for terminate IOLoop.instance() def terminate(): now = time.time() if now < deadline and (instance._callbacks or instance._timeouts): instance.add_timeout(now + 1, terminate) else: instance.stop() # After process all _callbacks and _timeouts, break IOLoop.instance() logging.info('Shutdown ...') # process recursion terminate() if options.test: return run_tests(application) if options.bootstrap_data or options.wipe_user_data: username = input("please input username: "******"Now serving on http://localhost:{0}".format(settings['site_port'])) tornado.ioloop.IOLoop.instance().start() logging.info('Exit ...')
def main(): """Main entry point for our application""" tornado.options.parse_command_line() settings = initialize_settings() application = make_application(settings) httpserver = HTTPServer(application, xheaders=True) max_wait_seconds_before_shutdown = 0 # signal handler def sig_handler(sig, frame): logging.warn("Caught Signal: {0}".format(sig)) tornado.ioloop.IOLoop.instance().add_callback(shutdown) # signal handler's callback def shutdown(): logging.info("Stopping HttpServer ...") httpserver.stop() # No longer accept new http traffic instance = tornado.ioloop.IOLoop.instance() deadline = time.time() + max_wait_seconds_before_shutdown # recursion for terminate IOLoop.instance() def terminate(): now = time.time() if now < deadline: instance.add_timeout(now + 1, terminate) else: instance.stop() logging.info('Shutdown ...') terminate() if options.test: return run_tests(application) if options.backup: remove = "rm -rf rethinkdb_dump*" backup = "rethinkdb dump -e {0}".format(settings['database_name']) os.system(remove) return os.system(backup) if options.restore != '': restore = "rethinkdb restore {0} --force".format(options.restore) return os.system(restore) if options.digest != '': return digest(options.digest, settings['database_name'], settings['conn']) if options.associate: return associate(settings['database_name'], settings['conn']) if options.overtime: return overtime(settings['database_name'], settings['conn']) if options.cleanup: return cleanup(settings['database_name'], settings['conn']) if options.foobar: return foobar(settings['database_name'], settings['conn']) if options.debug: httpserver.listen(settings['site_port']) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) else: httpserver.start(1) logging.info("Now serving on http://localhost:{0}".format(settings['site_port'])) tornado.ioloop.IOLoop.current().start() logging.info('Exit ...')
def main(): """Main entry point for our application""" tornado.options.parse_command_line() settings = initialize_settings() application = make_application(settings) httpserver = HTTPServer(application, xheaders=True) max_wait_seconds_before_shutdown = 0 # signal handler def sig_handler(sig, frame): logging.warn("Caught Signal: {0}".format(sig)) tornado.ioloop.IOLoop.instance().add_callback(shutdown) # signal handler's callback def shutdown(): logging.info("Stopping HttpServer ...") httpserver.stop() # No longer accept new http traffic instance = tornado.ioloop.IOLoop.instance() deadline = time.time() + max_wait_seconds_before_shutdown # recursion for terminate IOLoop.instance() def terminate(): now = time.time() if now < deadline: instance.add_timeout(now + 1, terminate) else: instance.stop() logging.info('Shutdown ...') terminate() if options.test: return run_tests(application) if options.backup: remove = "rm -rf rethinkdb_dump*" backup = "rethinkdb dump -e {0}".format(settings['database_name']) os.system(remove) return os.system(backup) if options.restore != '': restore = "rethinkdb restore {0} --force".format(options.restore) return os.system(restore) if options.digest != '': return digest(options.digest, settings['database_name'], settings['conn']) if options.associate: return associate(settings['database_name'], settings['conn']) if options.overtime: return overtime(settings['database_name'], settings['conn']) if options.cleanup: return cleanup(settings['database_name'], settings['conn']) if options.foobar: return foobar(settings['database_name'], settings['conn']) if options.debug: httpserver.listen(settings['site_port']) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) else: httpserver.start(1) logging.info("Now serving on http://localhost:{0}".format( settings['site_port'])) tornado.ioloop.IOLoop.current().start() logging.info('Exit ...')
def main(): tornado.options.parse_command_line() settings = initialize_settings() application = make_application(settings) httpserver = HTTPServer(application, xheaders=True) # signal handler def sig_handler(sig, frame): logging.warn("Caught Signal: %s" % sig) tornado.ioloop.IOLoop.instance().add_callback(shutdown) # signal handler's callback def shutdown(): logging.info("Stopping HttpServer ...") httpserver.stop() # No longer accept new http traffic instance = tornado.ioloop.IOLoop.instance() deadline = time.time() + settings['sigint_timeout'] # recursion for terminate IOLoop.instance() def terminate(): now = time.time() if now < deadline and (instance._callbacks or instance._timeouts): instance.add_timeout(now + 1, terminate) else: instance.stop() # After process all _callbacks and _timeouts, break IOLoop.instance() logging.info('Shutdown ...') # process recursion terminate() if options.test: return run_tests(application) if options.bootstrap_data or options.wipe_user_data: username = input("please input username: "******"rm -rf rethinkdb_dump*" backup = "rethinkdb dump -e {0}".format(settings['database_name']) os.system(remove) return os.system(backup) if options.dump: filename = 'static/dump/scq_dump.tar.gz' remove = "rm static/dump/scq_dump*" db = settings['database_name'] e_db = ' -e ' + db + '.' tables = ['Survey', 'Question', 'QuestionResponse', 'SurveyResponse', 'Group'] backup_tables = e_db.join(tables) backup_tables = e_db + backup_tables backup = "rethinkdb dump {0} -f {1}".format(backup_tables, filename) logging.info(backup) os.system(remove) return os.system(backup) if options.debug: httpserver.listen(settings['site_port']) signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) else: httpserver.bind(settings['site_port']) # port httpserver.start(0) logging.info("Now serving on http://localhost:{0}".format(settings['site_port'])) tornado.ioloop.IOLoop.instance().start() logging.info('Exit ...')