我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用tornado.options.options.host()。
def run_cmd(self, command, pattern): self.runner.run('shell', command, pattern=pattern) ExecLog(host=self.asset_name_str, cmd=self.command, user=self.user.username, remote_ip=self.remote_ip, result=self.runner.results).save() newline_pattern = re.compile(r'\n') for k, v in self.runner.results.items(): for host, output in v.items(): output = newline_pattern.sub('<br />', output) if k == 'ok': header = "<span style='color: green'>[ %s => %s]</span>\n" % (host, 'Ok') else: header = "<span style='color: red'>[ %s => %s]</span>\n" % (host, 'failed') self.write_message(header) self.write_message(output) self.write_message('\n~o~ Task finished ~o~\n')
def __init__(self): # register tornado's RequestHandler to designated context path handlers = [ (r'/publish', PublishHandler), (r'/subscribe', SubscribeHandler), (r'/', IndexHandler), ] settings = dict( template_path=path.join(path.dirname(__file__), 'templates'), static_path=path.join(path.dirname(__file__), 'static'), ) super(Application, self).__init__(handlers, **settings) # redis singeleton to share among handlers self.redis = redis.StrictRedis(host=options.redis_host, port=options.redis_port, db=options.redis_db, password=options.redis_password) # redis pubsub singeleton to share among handler(pubsub is used to subscribe channels) self.pubsub = self.redis.pubsub(ignore_subscribe_messages=True) self.pubsub.subscribe(options.redis_channel) # logger to record log self.logger = logger # base handler
def __init__(self): signal.signal(signal.SIGINT, self.intercept_signal) signal.signal(signal.SIGTERM, self.intercept_signal) self.logger = logging.getLogger(__name__) define("port", default=5000, help="run on the given port", type=int) define("host", default="0.0.0.0", help="run on the given host", type=str) self.config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "boxPrint.conf") tornado.options.parse_config_file(self.config_file) self.host = options.host self.port = options.port self.app = App()
def run(self): http_server = tornado.httpserver.HTTPServer(self.app) http_server.listen(self.port, self.host) self.logger.info("Mohou 3d print provider start.") tornado.ioloop.IOLoop.current().start()
def send_message(): stream = yield TCPClient().connect(options.host, options.port) yield stream.write((options.message + "\n").encode()) print("Sent to server:", options.message) reply = yield stream.read_until(b"\n") print("Response from server:", reply.decode().strip())
def main(): util.setup_trap() rpi.init() fpga.init() network.init(options.host, options.port) IOLoop.current().start()
def main(): tornado.options.parse_command_line() # create http server http_server = tornado.httpserver.HTTPServer(Application()) # serve the host and port pass by command line(or default 0.0.0.0:8000) http_server.listen(options.port, options.host) # start http server tornado.ioloop.IOLoop.current().start()