本文整理匯總了Python中gevent.pywsgi方法的典型用法代碼示例。如果您正苦於以下問題:Python gevent.pywsgi方法的具體用法?Python gevent.pywsgi怎麽用?Python gevent.pywsgi使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gevent
的用法示例。
在下文中一共展示了gevent.pywsgi方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: server_handler
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
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()
示例2: serve_forever
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
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()
示例3: run
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
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)
示例4: run_application
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
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
示例5: test_wsgi_scenario
# 需要導入模塊: import gevent [as 別名]
# 或者: from gevent import pywsgi [as 別名]
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.