Python gevent.pywsgi() Examples
The following are 5
code examples of gevent.pywsgi().
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
, or try the search function
.
Example #1
Source File: app.py From chainerui with MIT License | 5 votes |
def server_handler(args): """server_handler.""" if not db.setup(url=args.db, echo=args.db_echo): return if not _check_db_revision(): return app = create_app() listener = '{:s}:{:d}'.format(args.host, args.port) if args.debug: logging.getLogger('werkzeug').disabled = True set_loglevel(logging.DEBUG) app.config['ENV'] = 'development' app.debug = True _show_banner_debug(app, listener) from werkzeug.serving import run_simple run_simple( args.host, args.port, app, use_reloader=True, use_debugger=True, threaded=True) else: app.config['ENV'] = 'production' import gevent from gevent.pywsgi import WSGIServer http_server = WSGIServer(listener, application=app, log=None) def stop_server(): if http_server.started: http_server.stop() gevent.signal(signal.SIGTERM, stop_server) gevent.signal(signal.SIGINT, stop_server) logger.info(' * Environment: {}'.format(app.config['ENV'])) logger.info(' * Running on http://{}/ (Press CTRL+C to quit)'.format( listener)) try: http_server.serve_forever() except (KeyboardInterrupt, SystemExit): stop_server()
Example #2
Source File: WebManager.py From XiaQian with MIT License | 5 votes |
def serve_forever(): gevent.spawn(daemon) print web application = web.application(urls, globals()).wsgifunc() print 'Serving on 8888' server = gevent.pywsgi.WSGIServer(('', 8888), application) server.serve_forever()
Example #3
Source File: gateway_application_service.py From WavesGatewayFramework with MIT License | 5 votes |
def run(self) -> None: """ Starts all poller instances. After that, polling is performed in regular intervals specified by the polling_delay_ms property. By default this function blocks the current thread. """ self._validation_service.validate_all_addresses() self._logger.info("Gateway Application started") task_group = gevent.pool.Group() gevent.signal(signal.SIGINT, self._coin_transaction_polling_service.cancel) gevent.signal(signal.SIGINT, self._waves_transaction_polling_service.cancel) task_group.start(self._coin_transaction_polling_service) task_group.start(self._waves_transaction_polling_service) attempt_list_workers = self._create_attempt_list_workers() for worker in attempt_list_workers: gevent.signal(signal.SIGINT, worker.cancel) task_group.start(worker) http = gevent.pywsgi.WSGIServer( (self._host, self._port), self._flask, log=gevent.pywsgi.LoggingLogAdapter(self._logger.getChild('pywsgi'))) gevent.signal(signal.SIGINT, http.close) self._logger.info('Listening on %s:%s', self._host, str(self._port)) http.serve_forever() task_group.join(raise_error=True)
Example #4
Source File: server.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def run_application(self): path = self.environ.get('PATH_INFO') content_type = self.server.data_handlers.get(path) if content_type is not None: self.serve_file(basename(path), content_type) return websocket_mode = False if WebSocket.is_socket(self.environ): self.status = 'websocket' self.log_request() self.environ['websocket'] = WebSocket(self.environ, self.socket, self.rfile) websocket_mode = True try: self.result = self.application(self.environ, self.start_response) if self.result is not None: self.process_result() except: websocket = self.environ.get('websocket') if websocket is not None: websocket.close() raise finally: if websocket_mode: # we own the socket now, make sure pywsgi does not try to read from it: self.socket = None
Example #5
Source File: test_gipc.py From gipc with MIT License | 4 votes |
def test_wsgi_scenario(self): from gevent.pywsgi import WSGIServer def serve(http_server): http_server.serve_forever() def hello_world(environ, start_response): # Generate response in child process. with pipe() as (reader, writer): start_response('200 OK', [('Content-Type', 'text/html')]) rg = start_process( target=complchild_test_wsgi_scenario_respgen, args=(writer, )) response = reader.get() rg.join() assert rg.exitcode == 0 return [response] # Call `urlopen` with `None` in the parent before forking. This works # around a special type of segfault in the child after fork on MacOS. # Doh! See https://bugs.python.org/issue27126 and # https://github.com/jgehrcke/gipc/issues/52 try: import urllib.request as request except ImportError: import urllib2 as request try: result = request.urlopen(None) except AttributeError: pass http_server = WSGIServer(('localhost', 0), hello_world) servelet = gevent.spawn(serve, http_server) # Wait for server being bound to socket. while True: if http_server.address[1] != 0: break gevent.sleep(0.05) client = start_process( target=complchild_test_wsgi_scenario_client, args=(http_server.address, )) client.join() assert client.exitcode == 0 servelet.kill() servelet.get() # get() is join and re-raises Exception.