本文整理汇总了Python中tornado.httpserver.HTTPServer.bind方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPServer.bind方法的具体用法?Python HTTPServer.bind怎么用?Python HTTPServer.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.httpserver.HTTPServer
的用法示例。
在下文中一共展示了HTTPServer.bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpotifyServer
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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))
示例2: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [as 别名]
def main():
app = Application(handlers, **site_setting)
server = HTTPServer(app)
server.bind(port)
server.start()
IOLoop.instance().start()
示例3: serve
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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()
示例4: run
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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()
示例5: http_server
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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()
示例6: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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 --"
示例7: _init_infrastructures
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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'])
示例8: runserver
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [as 别名]
def runserver(args):
# set up logging to std out as default
logging.getLogger().setLevel(logging.DEBUG)
tornado.options.enable_pretty_logging()
# set up the Django app, TODO: move to webui module
wsgi_app = tornado.wsgi.WSGIContainer(django.core.handlers.wsgi.WSGIHandler())
# this guy tracks all the Remote Players
player_state = dict(state=ps.PlayerState())
application = tornado.web.Application([
(r'/api/1/content/(\d+)/data', StreamingContentHandler),
(r'/api/1/playback/players', ps.RemotePlayerListHandler , player_state),
url(r'/api/1/playback/players/(\d+)', ps.RemotePlayerHandler, player_state, 'player'),
(r'/api/1/playback/players/register', ps.RemotePlayerSocket, player_state),
(r'/api/1/playback/sessions', ps.SessionListHandler, player_state),
url(r'/api/1/playback/sessions/(\d+)', ps.SessionHandler, player_state, 'session'),
(r'.*', FallbackHandler, dict(fallback=wsgi_app))
], static_path=resource_filename('krum.webui', 'static'), # TODO: move to webui module
debug=True
)
server = HTTPServer(application)
server.bind(args.port)
server.start(1)
tornado.ioloop.IOLoop.instance().start()
示例9: run_server
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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)
示例10: multi_app
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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()
示例11: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [as 别名]
def main():
tornado.options.parse_command_line()
http_server = HTTPServer(Application(), xheaders=True)
http_server.bind(options.port, options.bind_ip)
http_server.start()
IOLoop.instance().start()
示例12: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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 --"
示例13: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [as 别名]
def main(arguments=None):
"""Runs thumbor server with the specified arguments."""
server_parameters = get_server_parameters(arguments)
lookup_paths = [os.curdir, expanduser("~"), "/etc/", dirname(__file__)]
config = Config.load(
server_parameters.config_path,
conf_name="thumbor.conf",
lookup_paths=lookup_paths,
)
logging.basicConfig(
level=getattr(logging, server_parameters.log_level.upper()),
format=config.THUMBOR_LOG_FORMAT,
datefmt=config.THUMBOR_LOG_DATE_FORMAT,
)
importer = Importer(config)
importer.import_modules()
if importer.error_handler_class is not None:
importer.error_handler = importer.error_handler_class(config)
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 = importer.import_class(server_parameters.app_class)(context)
server = HTTPServer(application)
if context.server.fd is not None:
fd_number = get_as_integer(context.server.fd)
if fd_number is None:
with open(context.server.fd, "r") as sock:
fd_number = sock.fileno()
sock = socket.fromfd(fd_number, socket.AF_UNIX, socket.SOCK_STREAM)
server.add_socket(sock)
else:
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("-- thumbor closed by user interruption --")
示例14: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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()
示例15: main
# 需要导入模块: from tornado.httpserver import HTTPServer [as 别名]
# 或者: from tornado.httpserver.HTTPServer import bind [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 --"