本文整理汇总了Python中werkzeug.serving.run_simple函数的典型用法代码示例。如果您正苦于以下问题:Python run_simple函数的具体用法?Python run_simple怎么用?Python run_simple使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_simple函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_command
def run_command(info, host, port, reload, debugger, eager_loading,
with_threads):
"""Runs a local development server for the Flask application."""
from werkzeug.serving import run_simple
if reload is None:
reload = info.debug
if debugger is None:
debugger = info.debug
if eager_loading is None:
eager_loading = not reload
app = info.make_wsgi_app(use_eager_loading=eager_loading)
# Extra startup messages. This depends a but on Werkzeug internals to
# not double execute when the reloader kicks in.
if os.environ.get('WERKZEUG_RUN_MAIN') != 'true':
# If we have an import path we can print it out now which can help
# people understand what's being served. If we do not have an
# import path because the app was loaded through a callback then
# we won't print anything.
if info.app_import_path is not None:
print(' * Serving Flask app "%s"' % info.app_import_path)
if info.debug is not None:
print(' * Forcing debug %s' % (info.debug and 'on' or 'off'))
run_simple(host, port, app, use_reloader=reload,
use_debugger=debugger, threaded=with_threads)
示例2: main
def main():
from docopt import docopt
from werkzeug.serving import run_simple
arguments = docopt(__doc__)
app = DapServer(arguments['<config.yaml>'])
run_simple(arguments['--ip'], int(arguments['--port']), app, use_reloader=True)
示例3: cmd_runserver
def cmd_runserver(self, listen='8000'):
from werkzeug.serving import run_simple
def view_index(request):
path = os.path.join(STATIC_FILES_DIR, 'index.html')
return Response(open(path, 'rb'), mimetype='text/html')
self.view_index = view_index
self.urls.add(Rule('/', endpoint='index'))
def view_generated(request, path):
endpoint = self.generated_files.get(path)
if endpoint is None:
raise NotFound
iterable = getattr(self, 'generate_' + endpoint)()
mimetype = mimetypes.guess_type(path)[0]
return Response(iterable, mimetype=mimetype)
self.view_generated = view_generated
self.urls.add(Rule('/static/<path:path>', endpoint='generated'))
if ':' in listen:
(address, port) = listen.rsplit(':', 1)
else:
(address, port) = ('localhost', listen)
run_simple(address, int(port), app, use_reloader=True, static_files={
'/static/': STATIC_FILES_DIR,
})
示例4: serve
def serve(port=8000, profile=False, site=None, sites_path='.'):
global application, _site, _sites_path
_site = site
_sites_path = sites_path
from werkzeug.serving import run_simple
if profile:
application = ProfilerMiddleware(application, sort_by=('cumtime', 'calls'))
if not os.environ.get('NO_STATICS'):
application = SharedDataMiddleware(application, {
b'/assets': os.path.join(sites_path, 'assets').encode("utf-8"),
})
application = StaticDataMiddleware(application, {
b'/files': os.path.abspath(sites_path).encode("utf-8")
})
application.debug = True
application.config = {
'SERVER_NAME': 'localhost:8000'
}
run_simple('0.0.0.0', int(port), application, use_reloader=True,
use_debugger=True, use_evalex=True, threaded=True)
示例5: main
def main():
# comment out to improve logging
service.prepare_service(sys.argv)
# Workaround for an issue with the auto-reload used below in werkzeug
# Without it multiple health senders get started when werkzeug reloads
if not os.environ.get('WERKZEUG_RUN_MAIN'):
health_sender_proc = multiproc.Process(name='HM_sender',
target=health_daemon.run_sender,
args=(HM_SENDER_CMD_QUEUE,))
health_sender_proc.daemon = True
health_sender_proc.start()
# We will only enforce that the client cert is from the good authority
# todo(german): Watch this space for security improvements
ctx = OctaviaSSLContext(ssl.PROTOCOL_SSLv23)
ctx.load_cert_chain(CONF.amphora_agent.agent_server_cert,
ca=CONF.amphora_agent.agent_server_ca)
# This will trigger a reload if any files change and
# in particular the certificate file
serving.run_simple(hostname=CONF.haproxy_amphora.bind_host,
port=CONF.haproxy_amphora.bind_port,
application=server.app,
use_debugger=CONF.debug,
ssl_context=ctx,
use_reloader=True,
extra_files=[CONF.amphora_agent.agent_server_cert])
示例6: build_server
def build_server():
print 'start to build paste server'
eventlet.hubs.use_hub('poll')
eventlet.patcher.monkey_patch(all=False, socket=True)
app = load_app()
# Create the WSGI server and start it
#host, port = cfg.CONF.api.host, cfg.CONF.api.port
host = '0.0.0.0'
port = '8080'
#LOG.info(_('Starting server in PID %s') % os.getpid())
#LOG.info(_("Configuration:"))
#cfg.CONF.log_opt_values(LOG, logging.INFO)
if host == '0.0.0.0':
#LOG.info(_(
# 'serving on 0.0.0.0:%(sport)s, view at http://127.0.0.1:%(vport)s')
# % ({'sport': port, 'vport': port}))
print 'port %s'%port
else:
#LOG.info(_("serving on http://%(host)s:%(port)s") % (
# {'host': host, 'port': port}))
print 'host %s'%host
#workers = service.get_workers('api')
workers =1
#serving.run_simple(host, port,
# app, processes=workers, threaded=1)
serving.run_simple(host, port,
app, processes=workers)
"""
示例7: main
def main():
service.prepare_service(sys.argv)
gmr.TextGuruMeditation.setup_autorun(version)
# Enable object backporting via the conductor
base.MagnumObject.indirection_api = base.MagnumObjectIndirectionAPI()
app = api_app.load_app()
# Setup OSprofiler for WSGI service
profiler.setup('magnum-api', CONF.host)
# SSL configuration
use_ssl = CONF.api.enabled_ssl
# Create the WSGI server and start it
host, port = CONF.api.host, CONF.api.port
LOG.info(_LI('Starting server in PID %s'), os.getpid())
LOG.debug("Configuration:")
CONF.log_opt_values(LOG, logging.DEBUG)
LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'),
dict(proto="https" if use_ssl else "http", host=host, port=port))
workers = CONF.api.workers
if not workers:
workers = processutils.get_worker_count()
LOG.info(_LI('Server will handle each request in a new process up to'
' %s concurrent processes'), workers)
serving.run_simple(host, port, app, processes=workers,
ssl_context=_get_ssl_configs(use_ssl))
示例8: run
def run(self, host, port):
from werkzeug.serving import run_simple
from bbs import app
from bbs.orm import connect_db
connect_db()
run_simple(host, int(port), app, use_reloader=True, use_debugger=True)
示例9: run
def run(self):
self._host.run()
if self._port != 443:
run_simple(self._host_name, self._port, self, threaded=True)
else:
make_ssl_devcert('key', host=self._host_name)
run_simple(self._host_name, self._port, self, threaded=True, ssl_context=('key.crt', 'key.key'))
示例10: serverThread
def serverThread(self):
if self.threads > 1:
run_simple(
"localhost", self.port, self.serveApplication, threaded=True, processes=self.threads, use_debugger=False
)
else:
run_simple("localhost", self.port, self.serveApplication, use_debugger=False)
示例11: cmd_runserver
def cmd_runserver(self, listen='8000'):
from werkzeug.serving import run_simple
def view_index(request):
path = os.path.join(STATIC_FILES_DIR, 'index.html')
return Response(open(path, 'rb'), mimetype='text/html')
self.view_index = view_index
self.urls.add(Rule('/', endpoint='index'))
def view_generated(request, path):
for filename, func, _ in self.get_generated_files():
if path == filename:
mimetype = mimetypes.guess_type(path)[0]
return Response(func(), mimetype=mimetype)
raise NotFound
self.view_generated = view_generated
self.urls.add(Rule('/static/<path:path>', endpoint='generated'))
self.urls.add(Rule('/<any("serviceworker.js"):path>', endpoint='generated'))
if ':' in listen:
(address, port) = listen.rsplit(':', 1)
else:
(address, port) = ('localhost', listen)
run_simple(address, int(port), app, use_reloader=True, static_files={
'/static/': STATIC_FILES_DIR,
})
示例12: main
def main(app_root, options):
try:
index = imp.load_source('index', 'index.wsgi')
except IOError:
print "Seems you don't have an index.wsgi"
sys.exit(-1)
if not hasattr(index, 'application'):
print "application not found in index.wsgi"
sys.exit(-1)
if not callable(index.application):
print "application is not a callable"
sys.exit(-1)
statics = { '/static': os.path.join(app_root, 'static'),
'/media': os.path.join(app_root, 'media'),
'/favicon.ico': os.path.join(app_root, 'favicon.ico'),
}
# FIXME: All files under current directory
files = ['index.wsgi']
try:
run_simple('localhost', options.port, index.application,
use_reloader = True,
use_debugger = True,
extra_files = files,
static_files = statics)
except KeyboardInterrupt:
print "OK"
示例13: run
def run(self):
"""
Start the web server.
"""
run_simple(self.hostname, self.port, self.dispatch,
threaded=True,
use_reloader=self.debug)
示例14: serve
def serve(port=8000, profile=False):
global application
from werkzeug.serving import run_simple
if profile:
application = ProfilerMiddleware(application)
run_simple('0.0.0.0', int(port), application, use_reloader=True,
use_debugger=True, use_evalex=True)
示例15: serve
def serve(port=8000, profile=False, site=None, sites_path='.'):
global application, _site, _sites_path
_site = site
_sites_path = sites_path
from werkzeug.serving import run_simple
if profile:
application = ProfilerMiddleware(application, sort_by=('cumtime', 'calls'))
if not os.environ.get('NO_STATICS'):
application = SharedDataMiddleware(application, {
'/assets': os.path.join(sites_path, 'assets'),
})
application = StaticDataMiddleware(application, {
'/files': os.path.abspath(sites_path)
})
application.debug = True
application.config = {
'SERVER_NAME': 'localhost:8000'
}
in_test_env = os.environ.get('CI')
if in_test_env:
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
run_simple('0.0.0.0', int(port), application,
use_reloader=not in_test_env,
use_debugger=not in_test_env,
use_evalex=not in_test_env,
threaded=True)