本文整理汇总了Python中tornado.httpserver.HTTPServer.start方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPServer.start方法的具体用法?Python HTTPServer.start怎么用?Python HTTPServer.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.httpserver.HTTPServer
的用法示例。
在下文中一共展示了HTTPServer.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def run(self):
#
# 启动 Tornado HTTP server。
#
# 当 DEBUG = False 时,启动多进程模式。
# 当 DEBUG = True 时,修改的模块自动重载。
#
from os import getpid
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
app = Application(self._get_handlers(), **self._get_settings())
server = HTTPServer(app)
port = settings.PORT
if settings.DEBUG:
server.listen(port)
IOLoop.instance().start()
else:
# 多进程模式
server.bind(port)
server.start(0)
print " * Sub Process: {0}".format(getpid())
IOLoop.instance().start()
示例2: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def main():
app = Application(handlers, **site_setting)
server = HTTPServer(app)
server.bind(port)
server.start()
IOLoop.instance().start()
示例3: _init_infrastructures
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def _init_infrastructures(self):
multiprocessing = False
if settings['PROCESSES'] and settings['PROCESSES'] > 1:
if settings['DEBUG']:
app_log.info('Multiprocess could not be used in debug mode')
else:
multiprocessing = True
if self.io_loop:
if not self.io_loop.initialized():
# this means self.io_loop is a customized io_loop, so `install` should be called
# to make it the singleton instance
#print self.io_loop.__class__.__name__
self.io_loop.install()
else:
# NOTE To support running tornado for multiple processes, we do not instance ioloop if multiprocessing is True
if not multiprocessing:
self.io_loop = IOLoop.instance()
application = self._make_application()
http_server_options = self.get_httpserver_options()
http_server = HTTPServer(application, io_loop=self.io_loop, **http_server_options)
listen_kwargs = {}
if settings.get('ADDRESS'):
listen_kwargs['address'] = settings.get('ADDRESS')
if multiprocessing:
# Multiprocessing mode
try:
http_server.bind(settings['PORT'], **listen_kwargs)
except socket.error, e:
app_log.warning('socket.error detected on http_server.listen, set ADDRESS="0.0.0.0" in settings to avoid this problem')
raise e
http_server.start(settings['PROCESSES'])
示例4: serve
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def serve():
""" application entry point """
# configure the application
options = command_line_options()
log = configure_logging(options)
log.info("Starting application")
# create the server
routes = route.get_routes()
routes.append((r"/public/(.*)", StaticFileHandler, {"path": "public"}))
routes = routes + TornadioRouter(handlers.socketio.SocketIOHandler).urls
application = Application(routes,
debug=options.debug,
socket_io_port=8000)
server = HTTPServer(application)
server.bind(options.port, options.address)
if options.debug:
server.start(1)
else:
server.start(0)
# startup done, rock and roll
log.info("Application Ready")
IOLoop.instance().start()
示例5: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def main(arguments=None):
'''Runs thumbor server with the specified arguments.'''
server_parameters = get_server_parameters(arguments)
logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper()))
config = Config.load(server_parameters.config_path)
importer = Importer(config)
importer.import_modules()
if server_parameters.security_key is not None:
config.SECURITY_KEY = server_parameters.security_key
if not isinstance(config.SECURITY_KEY, basestring):
raise RuntimeError('No security key was found for this instance of thumbor. Please provide one using the conf file or a security key file.')
context = Context(server=server_parameters, config=config, importer=importer)
application = ThumborServiceApp(context)
server = HTTPServer(application)
server.bind(context.server.port, context.server.ip)
server.start(1)
try:
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print
print "-- thumbor closed by user interruption --"
示例6: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def main():
# We have settings?
if os.path.exists('settings.py'):
parse_config_file('settings.py')
# What about command line args?
parse_command_line()
ssl_options = {}
# Check SSL options
if (options.certfile and options.keyfile) and (os.path.exists(
os.path.abspath(options.certfile)) and os.path.exists(
os.path.abspath(options.keyfile))):
ssl_options['certfile'] = os.path.abspath(options.certfile)
ssl_options['keyfile'] = os.path.abspath(options.keyfile)
server = HTTPServer(app(), ssl_options=ssl_options or None)
if options.debug:
options.address = '127.0.0.1'
log.debug('Run application in debug mode on %s:%s.' % (options.address,
options.port))
server.listen(options.port, options.address)
else:
log.debug('Run application in normal mode on %s:%s.' % (options.address,
options.port))
server.bind(options.port, options.address)
server.start(0)
IOLoop.instance().start()
示例7: UIServer
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
class UIServer(object):
def __init__(self, project, prepare_stage, event_handler, io_loop):
assert event_handler is not None
assert io_loop is not None
self._application = UIApplication(project, prepare_stage, event_handler, io_loop)
self._http = HTTPServer(self._application, io_loop=io_loop)
# these would throw OSError on failure
sockets = bind_sockets(port=None, address='127.0.0.1')
self._port = None
for s in sockets:
# we have to find the ipv4 one
if s.family == socket.AF_INET:
self._port = s.getsockname()[1]
assert self._port is not None
self._http.add_sockets(sockets)
self._http.start(1)
@property
def port(self):
return self._port
@property
def url(self):
return "http://localhost:%d/" % self.port
def unlisten(self):
"""Permanently close down the HTTP server, no longer listen on any sockets."""
self._http.close_all_connections()
self._http.stop()
示例8: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def main(arguments=None):
'''Runs r³ server with the specified arguments.'''
parser = argparse.ArgumentParser(description='runs the application that processes stream requests for r³')
parser.add_argument('-b', '--bind', type=str, default='0.0.0.0', help='the ip that r³ will bind to')
parser.add_argument('-p', '--port', type=int, default=9999, help='the port that r³ will bind to')
parser.add_argument('-l', '--loglevel', type=str, default='warning', help='the log level that r³ will run under')
parser.add_argument('-i', '--hide-index-page', action='store_true', default=False, help='indicates whether r³ app should show the help page')
parser.add_argument('-d', '--debug', action='store_true', default=False, help='indicates whether r³ app should run in debug mode')
parser.add_argument('--redis-host', type=str, default='0.0.0.0', help='the ip that r³ will use to connect to redis')
parser.add_argument('--redis-port', type=int, default=6379, help='the port that r³ will use to connect to redis')
parser.add_argument('--redis-db', type=int, default=0, help='the database that r³ will use to connect to redis')
parser.add_argument('--redis-pass', type=str, default='', help='the password that r³ will use to connect to redis')
parser.add_argument('-c', '--config-file', type=str, help='the config file that r³ will use to load input stream classes and reducers', required=True)
args = parser.parse_args(arguments)
cfg = Config(args.config_file)
c = redis.StrictRedis(host=args.redis_host, port=args.redis_port, db=args.redis_db, password=args.redis_pass)
logging.basicConfig(level=getattr(logging, args.loglevel.upper()))
application = R3ServiceApp(redis=c, config=cfg, log_level=args.loglevel.upper(), debug=args.debug, show_index_page=not args.hide_index_page)
server = HTTPServer(application)
server.bind(args.port, args.bind)
server.start(1)
try:
logging.debug('r³ service app running at %s:%d' % (args.bind, args.port))
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print
print "-- r³ service app closed by user interruption --"
示例9: multi_app
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def multi_app():
settings = {
"static_path": os.path.join(os.path.dirname(__file__), "../static"),
#"cookie_secret": "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
#"login_url": "/login",
#"xsrf_cookies": True,
}
cwd = Path(__file__).absolute().ancestor(1)
config = ConfigParser.ConfigParser()
#config.read(Path(cwd, './conf/backend.conf'))
port = 8888
app = tornado.web.Application(handlers=[
(r'/', root_handler),
(r'/favicon.ico', root_handler),
(r'/reload', reload_handler),
(r'/restart', restart_handler),
(r'/se', Searcher.Search_Handler),
(r'/sehtml', Searcher.SearchHtml_Handler),
(r'/sug', SugIndexer.Sug_Handler),
], **settings)
http_server = HTTPServer(app)
http_server.bind(port)
http_server.start(0)
logger.error('listen port %s' % port)
IOLoop.instance().start()
示例10: http_server
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def http_server(application, options):
""" http server """
log.warn("Application is running in HTTP mode, this is insecure. Pass in the --certfile and --keyfile to use SSL.")
server = HTTPServer(application)
server.bind(options.port, options.address)
server.start()
示例11: run_server
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
async def run_server(context):
application = await get_application(context)
server = HTTPServer(application)
server.bind(context.server.port, context.server.host)
server.start(1)
示例12: SpotifyServer
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
class SpotifyServer(object):
''' The Spotify HTTP server that handles art and audio requests '''
art_path = "/art/"
track_path = "/track/"
def __init__(self, client, port = SERVER_PORT):
SpotifyHandler.client = client
app = Application([
("%s(.*).jpg" % self.art_path, ArtHandler),
("%s(.*).aiff" % self.track_path, TrackHandler)
])
self.server = HTTPServer(app, no_keep_alive = True)
self.client = client
self.port = port
def start(self):
Log("Starting HTTP server on port %s" % self.port)
self.server.bind(self.port)
self.server.start()
def get_art_url(self, uri):
return "http://%s:%d%s%s.jpg" % (
gethostname(), self.port, self.art_path, E(uri))
def get_track_url(self, uri):
return "http://%s:%d%s%s.aiff" % (
gethostname(), self.port, self.track_path, E(uri))
示例13: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def main(arguments=None):
"""Runs thumbor server with the specified arguments."""
server_parameters = get_server_parameters(arguments)
logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper()))
lookup_paths = [os.curdir, expanduser("~"), "/etc/", dirname(__file__)]
config = Config.load(server_parameters.config_path, conf_name="thumbor.conf", lookup_paths=lookup_paths)
importer = Importer(config)
importer.import_modules()
if server_parameters.security_key is None:
server_parameters.security_key = config.SECURITY_KEY
if not isinstance(server_parameters.security_key, basestring):
raise RuntimeError(
"No security key was found for this instance of thumbor. Please provide one using the conf file or a security key file."
)
context = Context(server=server_parameters, config=config, importer=importer)
application = ThumborServiceApp(context)
server = HTTPServer(application)
server.bind(context.server.port, context.server.ip)
server.start(1)
try:
logging.debug("thumbor running at %s:%d" % (context.server.ip, context.server.port))
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print
print "-- thumbor closed by user interruption --"
示例14: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
def main():
parse_command_line()
sock = socket.fromfd(options.fd, socket.AF_UNIX, socket.SOCK_STREAM)
server = HTTPServer(application)
server.add_socket(sock)
server.start(1)
tornado.ioloop.IOLoop.instance().start()
示例15: FakeAnacondaServer
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import start [as 别名]
class FakeAnacondaServer(object):
def __init__(self, io_loop, fail_these, expected_basename):
assert io_loop is not None
self.fail_these = fail_these
self.expected_basename = expected_basename
self._application = FakeAnacondaApplication(server=self, io_loop=io_loop)
self._http = HTTPServer(self._application, io_loop=io_loop)
# these would throw OSError on failure
sockets = bind_sockets(port=None, address='127.0.0.1')
self._port = None
for s in sockets:
# we have to find the ipv4 one
if s.family == socket.AF_INET:
self._port = s.getsockname()[1]
assert self._port is not None
self._http.add_sockets(sockets)
self._http.start(1)
@property
def port(self):
return self._port
@property
def url(self):
return "http://localhost:%d/" % self.port
def unlisten(self):
"""Permanently close down the HTTP server, no longer listen on any sockets."""
self._http.close_all_connections()
self._http.stop()