本文整理汇总了Python中waitress.serve函数的典型用法代码示例。如果您正苦于以下问题:Python serve函数的具体用法?Python serve怎么用?Python serve使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-w', '--waitress', action='store_true')
args = parser.parse_args()
config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "pywps.cfg")
processes = [
FeatureCount(),
SayHello(),
Centroids(),
UltimateQuestion(),
Sleep(),
Buffer(),
Area(),
Viewshed()
]
s = Server(processes=processes, config_file=config_file)
# TODO: need to spawn a different process for different server
if args.waitress:
import waitress
from pywps import configuration
configuration.load_configuration(config_file)
host = configuration.get_config_value('wps', 'serveraddress').split('://')[1]
port = int(configuration.get_config_value('wps', 'serverport'))
waitress.serve(s.app, host=host, port=port)
else:
s.run()
示例2: server_command
def server_command(args):
repository = args.repository
app.config.update(REPOSITORY=repository, SESSION_ID=args.session_id)
app.debug = args.debug
if args.no_worker:
app.config.update(USE_WORKER=False)
if args.profile:
try:
from linesman.middleware import make_linesman_middleware
except ImportError:
print('-P/--profile/--linesman option is available only when '
"linesman is installed", file=sys.stderr)
print('Try the following command:', file=sys.stderr)
print('\tpip install linesman', file=sys.stderr)
raise SystemExit
else:
print('Profiler (linesman) is available:',
'http://{0.host}:{0.port}/__profiler__/'.format(args))
app.wsgi_app = make_linesman_middleware(app.wsgi_app)
if args.debug:
app.wsgi_app = SassMiddleware(app.wsgi_app, {
'earthreader.web': ('static/scss/', 'static/css/')
})
app.run(host=args.host, port=args.port, debug=args.debug,
threaded=True)
else:
serve(app, host=args.host, port=args.port)
示例3: start
def start(args, kill = None):
config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "pywps.cfg")
processes = [
FeatureCount(),
SayHello(),
Centroids(),
UltimateQuestion(),
Sleep(),
Buffer(),
Area(),
Box(),
Warp()
]
s = Server(processes=processes, config_file=config_file)
# TODO: need to spawn a different process for different server
if args.waitress:
import waitress
from pywps import configuration
configuration.load_configuration(config_file)
host = configuration.get_config_value('wps', 'serveraddress').split('://')[1]
port = int(configuration.get_config_value('wps', 'serverport'))
waitress.serve(s.app, host=host, port=port)
else:
s.run()
示例4: takedown_app
def takedown_app(env, parsed_ns):
try:
from waitress import serve
except ImportError:
print("Waitress needed to run this script")
raise
_waitress_console_logging()
config = Configurator()
config.include('pyramid_chameleon')
msg = "We'll be back shortly. Sorry for the inconvenience!"
if parsed_ns.message:
msg = parsed_ns.message.decode('utf-8')
#Figure out template path
if ':' in parsed_ns.template or parsed_ns.template.startswith('/'):
tpl = parsed_ns.template
else:
#Expect relative path
tpl = os.path.join(os.getcwd(), parsed_ns.template)
view = TakedownView(msg, tpl)
#Test rendering to cause exception early
view(env['request'])
print ("Serving template from: %s" % tpl)
takedown_view = TakedownView(msg, tpl)
config.add_view(takedown_view, context=HTTPNotFound)
print("Takedown app running... press ctrl+c to quit")
app = config.make_wsgi_app()
#Figure out port or socket
kwargs = {}
if ':' in parsed_ns.listen:
kwargs['listen'] = parsed_ns.listen
else:
kwargs['unix_socket'] = parsed_ns.listen
kwargs['unix_socket_perms'] = '666'
serve(app, **kwargs)
示例5: main
def main():
api = falcon.API()
api.add_route('/heka', HekaEndPoint())
serve(api, host='0.0.0.0', port=6227, _quiet=False)
示例6: main
def main():
insta = Instagram()
recent_instagrams = insta.recent_images()
app = create_app()
serve(app, port=9845)
示例7: serve
def serve(self, host='0.0.0.0', port=8080):
"""
Launch the WSGI app development web server
"""
import waitress
logger.info("{}:{}".format(host, port))
waitress.serve(self.app, host=host, port=port, _quiet=True)
示例8: run
def run():
if len(sys.argv) != 2:
sys.stderr.write("Usage: %s <config_file>\n" % (sys.argv[0],))
sys.exit(1)
settings = {'db_filename': './acss.db', 'server_host': 'localhost',
'server_port': 8081}
settings.update(json.loads(open(sys.argv[1]).read()))
config = Configurator(settings=settings)
def add_db(request, reify=True):
return DB(request.registry.settings.get('db_filename'))
config.add_request_method(add_db, 'db')
config.add_route('api_tracks', '/api/tracks')
config.add_route('api_track_bestlaps', '/api/tracks/{track_name}/bestlaps')
config.add_route('api_track_bestlaps_with_cars', '/api/tracks/{track_name}/{car_names}/bestlaps')
config.add_route('api_server_info', '/api/server_info')
config.add_view(api_tracks, route_name='api_tracks', renderer='json')
config.add_view(api_track_bestlaps, route_name='api_track_bestlaps',
renderer='json')
config.add_view(api_track_bestlaps_with_cars,
route_name='api_track_bestlaps_with_cars', renderer='json')
config.add_view(api_server_info, route_name='api_server_info',
renderer='json')
app = config.make_wsgi_app()
serve(app, host='0.0.0.0', port=8001)
示例9: Main
def Main():
args = ParseArguments()
if args.stdout is not None:
sys.stdout = open( args.stdout, 'w' )
if args.stderr is not None:
sys.stderr = open( args.stderr, 'w' )
SetupLogging( args.log )
options = SetupOptions( args.options_file )
# This ensures that ycm_core is not loaded before extra conf
# preload was run.
YcmCoreSanityCheck()
extra_conf_store.CallGlobalExtraConfYcmCorePreloadIfExists()
PossiblyDetachFromTerminal()
# This can't be a top-level import because it transitively imports
# ycm_core which we want to be imported ONLY after extra conf
# preload has executed.
from ycmd import handlers
handlers.UpdateUserOptions( options )
SetUpSignalHandler(args.stdout, args.stderr, args.keep_logfiles)
handlers.app.install( WatchdogPlugin( args.idle_suicide_seconds ) )
handlers.app.install( HmacPlugin( options[ 'hmac_secret' ] ) )
CloseStdin()
waitress.serve( handlers.app,
host = args.host,
port = args.port,
threads = 30 )
示例10: main
def main():
parser = argparse.ArgumentParser(
description=('Command-line interface for running the '
'RasmusMediaWeb server'),
)
parser.add_argument(
'-p', '--port',
default='8888',
help='Port to listen on (default: 8888)',
)
parser.add_argument(
'-i', '--interface',
default='0.0.0.0',
help='Interface to listen on (default: 0.0.0.0)',
)
parser.add_argument(
'--prefix',
help='Serve app at a prefixed url',
)
args = parser.parse_args()
kwargs = {
'host': args.interface,
'port': args.port,
}
if args.prefix:
kwargs['url_prefix'] = args.prefix
serve(make_app(), **kwargs)
示例11: server
def server(reload=False):
"Run the server"
if reload:
reload_me("server")
else:
serve(app, host=app.config["HOST"], port=app.config["PORT"],
threads=app.config["THREADS"])
示例12: run
def run(self, host='127.0.0.1', port=5000):
from waitress import serve
try:
serve(self, host=host, port=port)
except Exception as e:
raise RuntimeError("Unable to start server on "
"{}:{} ({})".format(host, port, e))
示例13: wsgi_run
def wsgi_run(app, opts, args):
""" """
serve(app,
host=opts.host,
port=opts.port
)
示例14: api_server
def api_server(ctx, bind, workers):
"""
Starts the nidaba API server using gunicorn.
"""
try:
from nidaba import api
from nidaba import web
except IOError as e:
if e.errno == 2:
click.echo('No configuration file found at {}'.format(e.filename))
ctx.exit()
import logging
from waitress import serve
from flask import Flask
logging.basicConfig(level=logging.DEBUG)
app = Flask('nidaba')
app.register_blueprint(api.get_blueprint())
app.register_blueprint(web.get_blueprint())
serve(app, listen=' '.join(bind).encode('utf-8'), threads=workers)
示例15: run_server
def run_server(config):
setup_app(config)
setup_logging(config)
# Initialize huey task queue
global task_queue
db_location = os.path.join(config.config_dir(), 'queue.db')
task_queue = SqliteHuey(location=db_location)
consumer = Consumer(task_queue)
ip_address = get_ip_address()
if (app.config['standalone'] and ip_address
and config['driver'].get() in ['chdkcamera', 'a2200']):
# Display the address of the web interface on the camera displays
try:
for cam in get_devices(config):
cam.show_textbox(
"\n You can now access the web interface at:"
"\n\n\n http://{0}:5000".format(ip_address))
except:
logger.warn("No devices could be found at startup.")
# Start task consumer
consumer.start()
try:
import waitress
# NOTE: We spin up this obscene number of threads since we have
# some long-polling going on, which will always block
# one worker thread.
waitress.serve(app, port=5000, threads=16)
finally:
consumer.shutdown()
if app.config['DEBUG']:
logger.info("Waiting for remaining connections to close...")