我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用gevent.pywsgi.WSGIServer()。
def __init__(self, volume_manager, context): """ Args: volume_manager (VolumeManager): The repository object to work with the volumes context (dict): A dict containing `host` and `port` """ self._api_loop = None self._api_server = None self._started = False self._connection = ('', 5000) try: self._connection = (context['host'], int(context['port'])) except (KeyError, ValueError) as error: print('Context provided to api erroneous: {}, defaulting: {}\n{}'.format(context, self._connection, error)) self.flask_app = Api._create_app(volume_manager) self._api_server = WSGIServer(self._connection, self.flask_app)
def run(options): import gluon.main if options.password != '<recycle>': gluon.main.save_password(options.password, int(options.port)) if options.logging: application = gluon.main.appfactory(wsgiapp=gluon.main.wsgibase, logfilename='httpserver.log', profiler_dir=profiler) else: application = gluon.main.wsgibase address = (options.ip, int(options.port)) workers = options.workers spawn = workers and Pool(int(options.workers)) or 'default' ssl_args = dict() if options.ssl_private_key: ssl_args['keyfile'] = options.ssl_private_key if options.ssl_certificate: ssl_args['certfile'] = options.ssl_certificate server = pywsgi.WSGIServer( address, application, spawn=spawn, log=None, **ssl_args ) server.serve_forever()
def run(self, handler): context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) context.load_cert_chain(handler.certificate_file, handler.private_key_file) context.load_verify_locations(cafile=handler.certificate_file) context.load_verify_locations(cafile=handler.crl_file) context.options &= ssl.OP_NO_SSLv3 context.options &= ssl.OP_NO_SSLv2 context.verify_flags |= ssl.VERIFY_CRL_CHECK_LEAF context.verify_mode = ssl.CERT_OPTIONAL self.options['ssl_context'] = context logger.info('Starting server on host %s port %d.', self.host, self.port) server = pywsgi.WSGIServer( (self.host, self.port), handler, ssl_context=context, handler_class=RequestHandler, log=logger, error_log=logger, ) server.serve_forever()
def inner_run(self, *args, **options): # Check if we are using the correct database engine configuration. if db.connection.settings_dict['ENGINE'] != 'django_db_geventpool.backends.postgresql_psycopg2': raise exceptions.ImproperlyConfigured("Django REST Framework Reactive requires the geventpool database engine.") # Make the pool gevent-ready. pool.set_backend(GeventBackend()) # Register the event handler for receiving model updates from the Django ORM. event_handler = rpc.RedisObserverEventHandler() gevent.spawn(event_handler) # Prepare the RPC server. info = connection.get_queryobserver_settings() rpc_server = pywsgi.WSGIServer((info['host'], info['port']), application=rpc.WSGIObserverCommandHandler()) rpc_server.serve_forever()
def run(self, handler): # pragma: no cover import flup.server.fcgi self.options.setdefault('bindAddress', (self.host, self.port)) flup.server.fcgi.WSGIServer(handler, **self.options).run()
def run(self, app): # pragma: no cover from wsgiref.simple_server import make_server from wsgiref.simple_server import WSGIRequestHandler, WSGIServer import socket class FixedHandler(WSGIRequestHandler): def address_string(self): # Prevent reverse DNS lookups please. return self.client_address[0] def log_request(*args, **kw): if not self.quiet: return WSGIRequestHandler.log_request(*args, **kw) handler_cls = self.options.get('handler_class', FixedHandler) server_cls = self.options.get('server_class', WSGIServer) if ':' in self.host: # Fix wsgiref for IPv6 addresses. if getattr(server_cls, 'address_family') == socket.AF_INET: class server_cls(server_cls): address_family = socket.AF_INET6 self.srv = make_server(self.host, self.port, app, server_cls, handler_cls) self.port = self.srv.server_port # update port actual port (0 means random) try: self.srv.serve_forever() except KeyboardInterrupt: self.srv.server_close() # Prevent ResourceWarning: unclosed socket raise
def run(self, handler): from gevent import pywsgi, local if not isinstance(threading.local(), local.local): msg = "Bottle requires gevent.monkey.patch_all() (before import)" raise RuntimeError(msg) if self.quiet: self.options['log'] = None address = (self.host, self.port) server = pywsgi.WSGIServer(address, handler, **self.options) if 'BOTTLE_CHILD' in os.environ: import signal signal.signal(signal.SIGINT, lambda s, f: server.stop()) server.serve_forever()
def main(): # socketio.run(app) from gevent import pywsgi from geventwebsocket.handler import WebSocketHandler server = pywsgi.WSGIServer(('', 5050), app, handler_class=WebSocketHandler) server.serve_forever()
def start_server(): from gevent import pywsgi from geventwebsocket.handler import WebSocketHandler server = pywsgi.WSGIServer(('', 5000), app, handler_class=WebSocketHandler) server.serve_forever()
def _run_app(self, crt_path=None, key_path=None): Logger.info('AppController: _run_app:') try: gevent_kwargs = { 'log': AppController.GeventLoggerInfo, 'error_log': AppController.GeventLoggerError} if crt_path and key_path: found_ssl = True for x in (crt_path, key_path): if not os.path.exists(x): found_ssl = False if found_ssl: gevent_kwargs['certfile'] = crt_path gevent_kwargs['keyfile'] = key_path else: Logger.warning('AppController: _run_app: cert and key ' 'were not found, starting without') self.ip = '0.0.0.0' self.port = 5000 self.using_ssl = found_ssl self.server = pywsgi.WSGIServer( (self.ip, self.port), app, **gevent_kwargs) self._set_started_true() self.server.serve_forever() except: Logger.error('AppController: %s' % traceback.format_exc())
def run_gevent_server(app, port): from gevent.pywsgi import WSGIServer import gevent.monkey gevent.monkey.patch_all() log.info("Activating gevent server on port %s", port) http_server = WSGIServer(('', port), app) http_server.serve_forever()
def start(self): handler = self.handleRequest if config.debug: # Auto reload UiRequest on change from Debug import DebugReloader DebugReloader(self.reload) # Werkzeug Debugger try: from werkzeug.debug import DebuggedApplication handler = DebuggedApplication(self.handleRequest, evalex=True) except Exception, err: self.log.info("%s: For debugging please download Werkzeug (http://werkzeug.pocoo.org/)" % err) from Debug import DebugReloader self.log.write = lambda msg: self.log.debug(msg.strip()) # For Wsgi access.log self.log.info("--------------------------------------") self.log.info("Web interface: http://%s:%s/" % (config.ui_ip, config.ui_port)) self.log.info("--------------------------------------") if config.open_browser: logging.info("Opening browser: %s...", config.open_browser) import webbrowser if config.open_browser == "default_browser": browser = webbrowser.get() else: browser = webbrowser.get(config.open_browser) browser.open("http://%s:%s" % (config.ui_ip if config.ui_ip != "*" else "127.0.0.1", config.ui_port), new=2) self.server = WSGIServer((self.ip.replace("*", ""), self.port), handler, handler_class=UiWSGIHandler, log=self.log) self.server.sockets = {} try: self.server.serve_forever() except Exception, err: self.log.error("Web interface bind error, must be running already, exiting.... %s" % err) sys.modules["main"].file_server.stop() self.log.debug("Stopped.")
def flup(app, address, **options): import flup.server.fcgi flup.server.fcgi.WSGIServer(app, bindAddress=address).run()
def gevent(app, address, **options): options = options['options'] workers = options.workers from gevent import pywsgi from gevent.pool import Pool pywsgi.WSGIServer(address, app, spawn=workers and Pool( int(options.workers)) or 'default', log=None).serve_forever()
def pulsar(app, address, **options): from pulsar.apps import wsgi sys.argv = ['anyserver.py'] s = wsgi.WSGIServer(callable=app, bind="%s:%d" % address) s.start()
def run(self, handler): server = pywsgi.WSGIServer((self.host, self.port), handler, handler_class=WebSocketHandler) if not self.quiet: server.logger = create_logger('geventwebsocket.logging') server.logger.setLevel(logging.INFO) server.logger.addHandler(logging.StreamHandler()) server.serve_forever()