def run(self, host=None, port=None, autoreload=None, debug=False): """Runs the application on a local development server. Args: host: the hostname to listen on. Defaults to ``'127.0.0.1'``. port: the port of the webserver. Defaults to ``5100`` or the port defined in the ``SERVER_NAME`` config variable if present. """ from wsgiref.simple_server import make_server if debug: settings.DEBUG = True self.autoreload = autoreload if host is None: host = '127.0.0.1' if port is None: server_name = settings.get('SERVER_NAME') if server_name and ':' in server_name: port = int(server_name.rsplit(':', 1)[1]) else: port = 5100 logging.info('application (%s) will start at %s:%s' % (self.document_root, host, port)) server = None def runner(): server = make_server(host, port, self) server.serve_forever() def stopper(): if server: server.shutdown() server.close() if autoreload: run_with_reloader(runner, stopper=stopper) else: runner()
advice_all() seconds = 0 if ichar == ord('h'): g_hide_all = not g_hide_all #screen.clear_win() seconds = 30 count = 0 break if ichar == ord('x'): g_show_all = not g_show_all g_show_exceptX = not g_show_exceptX advice_all() seconds = 0 finally: screen.unset_win() pass def profile_main(): try: screen.set_win() pp.preprocess_all(all_stocks, stockdata.sh_index, log_status) advice_all() finally: screen.unset_win() if __name__ == '__main__': from autoreload import run_with_reloader run_with_reloader(run_main)
#!/usr/bin/env python # -*- coding: utf-8 -*- """Runner for testing autoreload module.""" __author__ = "Wenjun Xiao" import os, time def runner(): print "[%s]enter..." % os.getpid() while 1: time.sleep(1) print "[%s]runner." % os.getpid() if __name__ == '__main__': from autoreload import run_with_reloader run_with_reloader(runner)
result = re.match(regex[0], args) if result: addr, port = regex[1](result) return addr, int(port) log.e('Invalid IP address or port !!!') exit(0) def main(): addr, port = '127.0.0.1', 8080 if len(sys.argv) > 1 : addr, port = parse_args() log.d("addr: {}:{}".format(addr, port)) s = socket(AF_INET, SOCK_STREAM) s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) try: s.bind((addr, port)) s.listen(10) while 1: global lis conn,addr = s.accept() log.i("connected by {}".format(addr)) thread.start_new_thread(switch_handler, (s, conn, addr)) finally: s.close() if __name__ == "__main__": autoreload.run_with_reloader(main)
#!/usr/bin/env python # -*- coding: utf-8 -*- """Runner for testing autoreload module.""" __author__="Wenjun Xiao" import os,time,sys def runner(name, debug): print "[%s]Enter..." % os.getpid() print "args:%s, debug:%s" % (name, debug) while 1: time.sleep(1) sys.stdout.flush() print "[%s]Exit." % os.getpid() if __name__ == '__main__': from autoreload import run_with_reloader run_with_reloader(runner, 'test reloader', debug=True)
#!/usr/bin/env python # -*- coding: utf-8 -*- """Runner for testing autoreload module.""" __author__="Wenjun Xiao" import os,time def runner(): print "[%s]enter..." % os.getpid() while 1: time.sleep(1) print "[%s]runner." % os.getpid() if __name__ == '__main__': from autoreload import run_with_reloader run_with_reloader(runner)