Python gevent.pywsgi.WSGIServer() Examples
The following are 30
code examples of gevent.pywsgi.WSGIServer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gevent.pywsgi
, or try the search function
.
Example #1
Source File: server.py From MoePhoto with Apache License 2.0 | 7 votes |
def runserver(taskInSender, taskOutReceiver, noteReceiver, stopEvent, mm, isWindows): global sender, receiver, noter sender = taskInSender receiver = taskOutReceiver noter = noteReceiver current.stopFlag = stopEvent mmView = memoryview(mm) if isWindows else mm.buf current.getPreview = lambda: BytesIO(mmView[:current.fileSize]) if not isWindows: mm = mm.buf.obj def writeFile(file): mm.seek(0) return file._file.readinto(mm) current.writeFile = writeFile def f(host, port): app.debug = False app.config['SERVER_NAME'] = None server = pywsgi.WSGIServer((host, port), app, environ={'SERVER_NAME': ''}) print('Current working directory: {}'.format(cwd)) print('Server starts to listen on http://{}:{}/, press Ctrl+C to exit.'.format(host, port)) server.serve_forever() return f
Example #2
Source File: test_cli.py From dagster with Apache License 2.0 | 6 votes |
def test_invoke_ui_with_port_taken(monkeypatch): def serve_forever(self): if self.server_port == 3000: raise OSError('Address already in use') monkeypatch.setattr(pywsgi.WSGIServer, 'serve_forever', serve_forever) runner = CliRunner() result = runner.invoke( ui, ['-f', file_relative_path(__file__, './pipeline.py'), '-a', 'test_repository'], input="n\n", ) assert result.exception result = runner.invoke( ui, ['-f', file_relative_path(__file__, './pipeline.py'), '-a', 'test_repository'], input="y\n", ) assert ':3001' in result.output
Example #3
Source File: websocket.py From pypkjs with MIT License | 6 votes |
def run(self): pebble_greenlet = self.pebble.connect() self.pebble.pebble.register_raw_inbound_handler(self._handle_inbound) self.pebble.pebble.register_raw_outbound_handler(self._handle_outbound) if self.pebble.timeline_is_supported: self.timeline.continuous_sync() self.timeline.do_maintenance() logging.getLogger().addHandler(WebsocketLogHandler(self, level=logging.WARNING)) if self.ssl_root is not None: ssl_args = { 'keyfile': '%s/server-key.pem' % self.ssl_root, 'certfile': '%s/server-cert.pem' % self.ssl_root, 'ca_certs': '%s/ca-cert.pem' % self.ssl_root, 'ssl_version': ssl.PROTOCOL_TLSv1, } else: ssl_args = {} self.server = pywsgi.WSGIServer(("", self.port), self.handle_ws, handler_class=WebSocketHandler, **ssl_args) gevent.spawn(self.server.serve_forever) pebble_greenlet.join() self.server.close() self.pebble.disconnect()
Example #4
Source File: weblcds.py From artisan with GNU General Public License v3.0 | 6 votes |
def work(p,rp,nonesym,timec,timebg,btc,btbg,etc,etbg,showetflag,showbtflag): global port, static_path, nonesymbol, timecolor, timebackground, btcolor, btbackground, etcolor, etbackground, showbt, showet port = p static_path = rp nonesymbol = nonesym timecolor = timec timebackground = timebg btcolor = btc btbackground = btbg etcolor = etc etbackground = etbg showet = showetflag showbt = showbtflag TEMPLATE_PATH.insert(0,rp) s = WSGIServer(("0.0.0.0", p), default_app(), handler_class=WebSocketHandler) s.serve_forever()
Example #5
Source File: chronograph.py From openprocurement.auction with Apache License 2.0 | 6 votes |
def init_web_app(self): self.web_application = chronograph_webapp self.web_application.chronograph = self location = self.config['main'].get('web_app') if ':' in str(location): if not location.startswith('//'): location = "//{}".format(location) o = urlparse(location) self.server = WSGIServer( get_lisener(o.port, o.hostname), self.web_application, spawn=100 ) else: self.server = WSGIServer( get_lisener(location), self.web_application, spawn=100 ) self.server.start()
Example #6
Source File: config_explorer.py From magnitude with MIT License | 6 votes |
def main(args): parser = argparse.ArgumentParser(description=u'Serve up a simple configuration wizard') parser.add_argument(u'--port', type=int, default=8123, help=u'port to serve the wizard on') parser.add_argument(u'--include-package', type=unicode, action=u'append', default=[], help=u'additional packages to include') args = parser.parse_args(args) app = make_app(args.include_package) CORS(app) http_server = WSGIServer((u'0.0.0.0', args.port), app) print("serving Config Explorer on port {args.port}") http_server.serve_forever()
Example #7
Source File: api.py From raiden-services with MIT License | 6 votes |
def __init__( self, monitoring_service: MonitoringService, operator: str, info_message: str = DEFAULT_INFO_MESSAGE, ) -> None: self.flask_app = Flask(__name__) self.api = ApiWithErrorHandler(self.flask_app) self.rest_server: Optional[WSGIServer] = None self.monitoring_service = monitoring_service self.operator = operator self.info_message = info_message resources: List[Tuple[str, Resource, str]] = [ ("/info", cast(Resource, InfoResource), "info"), ] for endpoint_url, resource, endpoint in resources: self.api.add_resource( resource, API_PATH + endpoint_url, resource_class_kwargs={"monitoring_service": monitoring_service, "api": self}, endpoint=endpoint, )
Example #8
Source File: run.py From psdash with Creative Commons Zero v1.0 Universal | 6 votes |
def _run_web(self): logger.info("Starting web server") log = 'default' if self.app.debug else None ssl_args = {} if self.app.config.get('PSDASH_HTTPS_KEYFILE') and self.app.config.get('PSDASH_HTTPS_CERTFILE'): ssl_args = { 'keyfile': self.app.config.get('PSDASH_HTTPS_KEYFILE'), 'certfile': self.app.config.get('PSDASH_HTTPS_CERTFILE') } listen_to = ( self.app.config.get('PSDASH_BIND_HOST', self.DEFAULT_BIND_HOST), self.app.config.get('PSDASH_PORT', self.DEFAULT_PORT) ) self.server = WSGIServer( listen_to, application=self.app, log=log, **ssl_args ) self.server.serve_forever()
Example #9
Source File: explanation_dashboard.py From interpret-community with MIT License | 5 votes |
def run(self): class devnull: write = lambda _: None # noqa: E731 server = WSGIServer((self.ip, self.port), self.app, log=devnull) self.app.config["server"] = server server.serve_forever() # Closes server on program exit, including freeing all sockets def closeserver(): server.stop() atexit.register(closeserver)
Example #10
Source File: bottle.py From slack-machine with MIT License | 5 votes |
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
Example #11
Source File: rest.py From blockade with Apache License 2.0 | 5 votes |
def start(data_dir='/tmp', port=5000, debug=False, host_exec=None): signal.signal(signal.SIGUSR2, stack_trace_handler) BlockadeManager.set_data_dir(data_dir) if host_exec: BlockadeManager.set_host_exec(host_exec) app.debug = debug http_server = WSGIServer(('', port), app) http_server.serve_forever() ############## ERROR HANDLERS ##############
Example #12
Source File: manage.py From mining with MIT License | 5 votes |
def runserver(port, ip, debug): if debug is None: server = WSGIServer((ip, port), app, handler_class=WebSocketHandler) server.serve_forever() click.echo(u'OpenMining start server at: {}:{}'.format(ip, port)) run(app=app, host=ip, port=port, debug=debug, reloader=True, server=GeventWebSocketServer)
Example #13
Source File: httphandler.py From taserver with GNU Affero General Public License v3.0 | 5 votes |
def run(self): server = pywsgi.WSGIServer(('0.0.0.0', self.ports['restapi']), self.handle_http_request) server.serve_forever()
Example #14
Source File: chain_api.py From son-emu with Apache License 2.0 | 5 votes |
def _start_flask(self): logging.info("Starting %s endpoint @ http://%s:%d" % ("ChainDummyApi", self.ip, self.port)) self.http_server = WSGIServer( (self.ip, self.port), self.app, log=open("/dev/null", "w") # don't show http logs ) self.http_server.serve_forever(stop_timeout=1) logging.info('Stopped %s' % self.__class__.__name__)
Example #15
Source File: web.py From RobotEyes with MIT License | 5 votes |
def start(base, res, host, port): global results global baseline results = res baseline = base app.logger.info('Starting server on %s:%s' % (host, port)) try: pywsgi.WSGIServer((host, int(port)), app).serve_forever() except KeyboardInterrupt: print('Exiting...')
Example #16
Source File: anyserver.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example #17
Source File: anyserver.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example #18
Source File: anyserver.py From termite-visualizations with BSD 3-Clause "New" or "Revised" License | 5 votes |
def flup(app, address, **options): import flup.server.fcgi flup.server.fcgi.WSGIServer(app, bindAddress=address).run()
Example #19
Source File: rest_api_endpoint.py From son-emu with Apache License 2.0 | 5 votes |
def _start_flask(self): # self.app.run(self.ip, self.port, debug=False, use_reloader=False) # this should be a more production-fit http-server # self.app.logger.setLevel(logging.ERROR) self.http_server = WSGIServer((self.ip, self.port), self.app, # This disables HTTP request logs to not # mess up the CLI when e.g. the # auto-updated dashboard is used log=open("/dev/null", "w") ) self.http_server.serve_forever()
Example #20
Source File: bottle.py From slack-machine with MIT License | 5 votes |
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()
Example #21
Source File: api.py From raiden-services with MIT License | 5 votes |
def run(self, host: str, port: int) -> None: self.rest_server = WSGIServer((host, port), self.flask_app) self.rest_server.start() log.info("Running endpoint", endpoint=f"http://{host}:{port}")
Example #22
Source File: api.py From raiden-services with MIT License | 5 votes |
def run(self, host: str, port: int) -> None: self.rest_server = WSGIServer((host, port), self.flask_app) self.rest_server.start() log.info("Running endpoint", endpoint=f"http://{host}:{port}")
Example #23
Source File: api.py From openbrokerapi with MIT License | 5 votes |
def serve(service_broker: ServiceBroker, credentials: Union[List[BrokerCredentials], BrokerCredentials, None], logger: logging.Logger = logging.root, port=5000, debug=False): """ Starts flask with the given brokers. You can provide a list or just one ServiceBroker :param service_broker: ServicesBroker for services to provide :param credentials: Username and password that will be required to communicate with service broker :param logger: Used for api logs. This will not influence Flasks logging behavior :param port: Port :param debug: Enables debugging in flask app """ from flask import Flask app = Flask(__name__) app.debug = debug blueprint = get_blueprint(service_broker, credentials, logger) logger.debug('Register openbrokerapi blueprint') app.register_blueprint(blueprint) try: from gevent.pywsgi import WSGIServer logger.info('Start Gevent server on 0.0.0.0:%s' % port) http_server = WSGIServer(('0.0.0.0', port), app) http_server.serve_forever() except ImportError: logger.info('Start Flask on 0.0.0.0:%s' % port) logger.warning('Use a server like gevent or gunicorn for production!') app.run('0.0.0.0', port)
Example #24
Source File: GrafanaDatastoreServer.py From grafana-redistimeseries with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): global REDIS_POOL parser = argparse.ArgumentParser() parser.add_argument("--host", help="server address to listen to", default="0.0.0.0") parser.add_argument("--port", help="port number to listen to", default=8080, type=int) parser.add_argument("--redis-server", help="redis server address", default="localhost") parser.add_argument("--redis-port", help="redis server port", default=6379, type=int) args = parser.parse_args() REDIS_POOL = redis.ConnectionPool(host=args.redis_server, port=args.redis_port) http_server = WSGIServer(('', args.port), app) http_server.serve_forever()
Example #25
Source File: http_server.py From ns4_chatbot with Apache License 2.0 | 5 votes |
def _startup(self): self.__url_mapping() logger.info("Web服务启动了,端口:%d",self.config.http_port) http_server = WSGIServer(('0.0.0.0', self.config.http_port), self.app) try: http_server.serve_forever() except Exception as e: logger.exception(e,"Web服务启动发生错误:%s",str(e))
Example #26
Source File: server.py From youtube-dl-nas with MIT License | 5 votes |
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()
Example #27
Source File: FlaskAPI.py From kalliope with GNU General Public License v3.0 | 5 votes |
def run(self): http_server = WSGIServer(('', 5000), self.app) http_server.serve_forever()
Example #28
Source File: bottle.py From warriorframework with Apache License 2.0 | 5 votes |
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()
Example #29
Source File: bottle.py From warriorframework with Apache License 2.0 | 5 votes |
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
Example #30
Source File: bottle.py From warriorframework with Apache License 2.0 | 5 votes |
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()