本文整理汇总了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.