def run(self, handler): from gunicorn.app.base import Application config = {'bind': "%s:%d" % (self.host, int(self.port))} config.update(self.options) class GunicornApplication(Application): def init(self, parser, opts, args): return config def load(self): return handler GunicornApplication().run()
def start_server(server='wsgiref', host=None, port=None, debug=False, config=None): if not server in WSGI_ADAPTERS: raise RuntimeError("Server '%s' is not a valid server. Valid servers are: " % server , ",".join(k for (k,v) in WSGI_ADAPTERS.items())) if config is None: config = {} if not host is None: config.update({'host':str(host)}) else: config.update({'host':'localhost'}) if not port is None: config.update({'port':int(port)}) else: config.update({'port':8080}) config.update({'debug':debug}) if not 'port' in config: raise RuntimeError("Startup error. Server Port must be specified") if not 'host' in config: raise RuntimeError("Startup error. Host Address must be specified") http_handler = None try: if not 'request_handler' in config: http_handler = DefaultHttpRequestHandler(debug_enabled=debug) else: http_handler = config['request_handler'] if not util.is_callable(http_handler) or not isinstance(http_handler, HttpRequestHandler): raise RuntimeError("Startup error. Specified request_handler is not valid adbobopy.web.HttpRequestHandler.") config.update({'request_handler':http_handler}) server_adapter = WSGI_ADAPTERS[server] config.update({'server':server}) print print 'Starting AdoboPy Webserver' print 'Using run config options:' for k,v in config.items(): if 'request_handler' == k: v = v.__class__.__name__ else: v = str(v) print ' %s = %s' % (k, v) print print 'Use Ctrl-C to quit.' print server_adapter(config) except KeyboardInterrupt: print 'Server has been shutdowned' except (Exception, SystemExit, MemoryError): exc_type, exc_value, exc_traceback = sys.exc_info() print 'Shutting down due error encountered : ' traceback.print_exc()