def start(port=54000, address='127.0.0.1'): "Starts LiveStyle server on given port" stop() global httpserver logger.info('Starting LiveStyle server on port %s' % port) httpserver = tornado.httpserver.HTTPServer(application) httpserver.listen(port, address=address)
def main(): httpserver = tornado.httpserver.HTTPServer(Application()) port = 8898 if 'train_server_port' in cfg: port = cfg['train_server_port'] httpserver.listen(port) print 'running traing server on port:', port tornado.ioloop.IOLoop.instance().start()
def main(): arguments = argument_parser.parse_args() if arguments.db: capture_data() # tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(applicaton) httpserver.listen(options.port) tornado.ioloop.IOLoop.instance().start()
def main(): httpserver = tornado.httpserver.HTTPServer(Application()) port = 8898 if "train_server_port" in cfg: port = cfg["train_server_port"] httpserver.listen(port) print "running traing server on port:", port tornado.ioloop.IOLoop.instance().start()
def main(): tornado.options.parse_command_line() dir_name = os.path.dirname(__file__) path = os.path.join(dir_name, "settings_dev.py") tornado.options.parse_config_file(path) tornado.autoreload.add_reload_hook(lambda: "x") tornado.autoreload.start() httpserver = tornado.httpserver.HTTPServer(Application()) httpserver.listen(options.port) tornado.ioloop.IOLoop.instance().start()
def main(): tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(application) httpserver.listen(options.port) print 'Developmet sever is runnint at http://127.0.0.1:{}'.format( options.port) print 'Quit the sever with Ctrl-C' tornado.ioloop.IOLoop.instance().start()
def main(): initLogger(LOG_PATH, DEBUG) app = tornado.web.Application( handlers=[ (r'/query', QueryHandler), ] ) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(8000) tornado.ioloop.IOLoop.instance().start()
def test_wraps(): def exit_callback(): client = tornado.httpclient.AsyncHTTPClient() ret = client.fetch('http://localhost:8000/home/welcome') nose.tools.assert_is_not_none(ret) tornado.ioloop.IOLoop.current().stop() httpserver = tornado.httpserver.HTTPServer( blueprint.wraps(tornado.web.Application())) httpserver.listen(8000) ioloop = tornado.ioloop.IOLoop.current() ioloop.add_timeout(ioloop.time() + 1, exit_callback) ioloop.start()
def main(): app = Application() if (len(logger.handlers) > 0): formatter = logging.Formatter( "[%(levelname).1s %(asctime)s %(module)s:%(lineno)s] %(message)s", datefmt='%y%m%d %H:%M:%S') logger.handlers[0].setFormatter(formatter) if options.debug: logging.info('== Tornado in DEBUG mode ==============================') for key, cfg in settings.items(): logging.info(key + ' = ' + str(cfg)) logging.info('=======================================================') logging.info('Web App handlers:') for h in url_patterns: logging.info(str(h)) httpserver = tornado.httpserver.HTTPServer(app, xheaders=True) httpserver.listen(int(os.environ.get('PORT', options.port))) tornado.ioloop.IOLoop.instance().start()
def main(): device_registry = DeviceRegistry("registry.csv") registrion_handler = RegistrationHandler(device_registry) c2dm_facade = C2DMServiceFacade() wekup_handler = MDSWakeupHandler(c2dm_facade, device_registry) print("Will now start the c2dm application server") map(lambda x: options.define(*x), [ ("interface", "", str, "interface to listen on"), ("port", 8888, int, "port to listen on"), ("debug", False, bool, "run in debug mode"),]) options.parse_command_line() o = options.options application = WakeupMDSApplcations(registrion_handler, wekup_handler) httpserver = tornado.httpserver.HTTPServer(application) httpserver.listen(o.port, o.interface) ioloop = tornado.ioloop.IOLoop.instance() ioloop.start()
def main(): app = Application() if len(logger.handlers) > 0: formatter = logging.Formatter( "[%(levelname).1s %(asctime)s %(module)s:%(lineno)s] %(message)s", datefmt='%y%m%d %H:%M:%S') logger.handlers[0].setFormatter(formatter) if options.debug: logging.info('== Tornado in DEBUG mode ==============================') for key, cfg in settings.items(): logging.info(key + ' = ' + str(cfg)) logging.info('=======================================================') logging.info('Server listens on port: %d' % (options.port)) logging.info('API handlers:') for h in url_routes: logging.info(h) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(os.environ.get("PORT", options.port)) tornado.ioloop.IOLoop.instance().start()
word=word, means=word_info['means'].split('/'), ph=word_info['ph'].split('/')) else: means, ph = spider_word_by_name(word) print(means, ph) word_id = module.save_word(word=word, means=means, ph=ph) if word_id: print('保存成功', word, ph) print(means) self.render('search.html', word=word, means=means.split('/'), ph=ph.split('/')) else: self.write('保存失败') settings = { # "static_path": os.path.join(os.path.dirname(__file__),"static") 'static_path': os.path.join(os.path.dirname(__file__), 'static'), #静态文件 'template_path': os.path.join(os.path.dirname(__file__), 'template') #模板文件 } #配置静态文件路径 application = web.Application([(r'/', MainPageHandle), (r'/search', SearchHandler), (r'/list', ListPageHandle)], **settings) if __name__ == '__main__': httpserver = httpserver.HTTPServer(application) httpserver.listen(8087) ioloop.IOLoop.current().start()
def start(port): global httpserver logger.info('Starting LiveStyle server on port %s' % port) httpserver = tornado.httpserver.HTTPServer(application) httpserver.listen(port, address='127.0.0.1') threading.Thread(target=tornado.ioloop.IOLoop.instance().start).start()
def main(): app = App() httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(5025) tornado.ioloop.IOLoop.instance().start()
tornado.web.Application.__init__(self, handlers, **settings) class BaseHandler(tornado.web.RequestHandler): @property def db(self): return self.application.database class MainPageHandler(BaseHandler): def get(self): self.render('main_page.html') if __name__ == "__main__": if (len(sys.argv) != 2): print "error: missing config file" exit(0) config = load_config_file(sys.argv[1]) httpserver = tornado.httpserver.HTTPServer( Application( db.Database(config['database'], config['host'], config['user'], config['password']), config, ) ) httpserver.listen(int(config['port'])) print("Server listening port {}".format(config['port'])) tornado.ioloop.IOLoop.current().start()
print(responseVals) self.write(responseVals) self.finish() else: print('first request') print(responseCache) pass # todo: should probably validate stream names stream1 = self.get_query_argument('stream1') stream2 = self.get_query_argument('stream2') if stream1 and stream2: http_client = tornado.httpclient.AsyncHTTPClient() # if stream data is not in the cache, fetch next item if not responseCache.get(stream1): http_client.fetch(API_ENDPOINT + stream1, handle_request) if not responseCache.get(stream2): http_client.fetch(API_ENDPOINT + stream2, handle_request) else: self.send_error(400) self.finish if __name__ == "__main__": app = tornado.web.Application(handlers=[(r"/quiz/merge", MainHandler)], debug=True) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(8888) tornado.ioloop.IOLoop.instance().start()
# -*- coding: UTF-8 -*- import tornado.ioloop from tornado.web import Application import tornado.httpserver from setting import settings, conf_redis, logg_file, log_level import redis from urls import path from tornado.options import options, define define("port", default=8081, type=int, help="run server on the given port") class application(Application): def __init__(self, *args, **kwargs): super(application, self).__init__(*args, **kwargs) self.redis = redis.StrictRedis(**conf_redis) if __name__ == '__main__': app = application(path, **settings) options.log_file_prefix = logg_file options.logging = log_level tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(app) #创建HTTP服务器 httpserver.listen(options.port, address="127.0.0.1") # tornado.ioloop.IOLoop.current().start() #启动ellp轮询绑定80端口
def main(): tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(Application()) httpserver.listen(options.port, options.host) tornado.ioloop.IOLoop.instance().start()
self.write('%s \r\n' % msg) class Test2Handler(tornado.web.RequestHandler): @gen.coroutine def get(self): t1 = self.get_argument('t1', 5) t2 = self.get_argument('t2', 3) fetchMsg(t1, callback = (yield gen.Callback('t1'))) fetchMsg(t2, callback = (yield gen.Callback('t2'))) r1, r2 = yield gen.WaitAll(('t1', 't2')) self.write(r1 + ',' + r2 + '\r\n') if __name__ == '__main__': tornado.options.parse_command_line() app = tornado.web.Application( handlers=[ (r'/', IndexHandler), (r'/reverse/(\w+)', ReverseHandler), (r'/test1', Test1Handler), (r'/test2', Test2Handler), (r'/test3', Test3Handler), ] ) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(8000) tornado.ioloop.IOLoop.instance().start()
import tornado.web import tornado.ioloop import tornado.httpserver import tornado.options import os.path from tornado.options import define,options define('port',default=8000,type=int,help='run on the given port') class Application(tornado.web.Application): def __init__(self): hls = [(r'/',IndexHandler)] settings = dict( template_path = os.path.join(os.path.dirname(__file__),"templates"), static_path = os.path.join(os.path.dirname(__file__),'static'), debug=True, ) tornado.web.Application.__init__(self,hls,**settings) class IndexHandler(tornado.web.RequestHandler): def get(self): self.render('index.html', header_text='welcome user!', page_title="burt's books") if __name__ == "__main__": tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(Application()) httpserver.listen(options.port) tornado.ioloop.IOLoop.instance().start()
def start_server(port): global httpserver logger.info('Starting LiveStyle server on port %s' % port) httpserver = tornado.httpserver.HTTPServer(application) httpserver.listen(port, address='127.0.0.1') threading.Thread(target=tornado.ioloop.IOLoop.instance().start).start()
(r'/', IndexHandler), (r'/post/detail/([-\w]+)(/?)', PostDetailHandler), (r'/login/', LoginHandler), (r'/logout/', LogoutHandler) ] server_settings = { 'debug': settings.DEBUG, 'title': settings.TITLE, 'template_path': settings.TEMPLATE_PATH, 'static_path': settings.STATIC_PATH, 'cookie_secret': settings.COOKIE_SECRET, 'login_url': '/login/', 'xsrf_cookies': True, 'autoescape': None } tornado.web.Application.__init__(self, handlers, **server_settings) mongoengine.connect(**settings.DATABASE) if __name__ == '__main__': if settings.DEBUG: tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(Application()) httpserver.listen(settings.PORT) print("Listening, http://127.0.0.1:%s" % settings.PORT) tornado.ioloop.IOLoop.instance().start()
import tornado.web import tornado.ioloop import tornado.httpserver import logging import svr_util class BackHandler(tornado.web.RequestHandler): def get(self): self.write('hello, this is the back end') if __name__ == '__main__': svr_util.daemonize() logging.basicConfig(level=logging.DEBUG, filename='/tmp/booknote.py.log') app = tornado.web.Application(handlers = [(r'/req', BackHandler)]) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(8080, '127.0.0.1') logging.info('start service on port 8080') tornado.ioloop.IOLoop.instance().start()
def main(): app = Myapplication() httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(config.options.get("port")) httpserver.start() tornado.ioloop.IOLoop.current().start()
def on_message(self, message): print(message) if message.startswith('name:'): self.name = message.split(':')[1] else: data = {'name': self.name, 'message': message, 'timestamp': str(datetime.now().strftime('%Y-%m-%d %H.%M.%S'))} for socket in player_sockets: if socket != self: socket.write_message(data) self.write_message(json.dumps(data)) def load_config_file(config_file): with open(config_file, 'r') as f: return json.load(f) if __name__ == "__main__": if (len(sys.argv) != 2): print ("error: missing config file") exit(0) config = load_config_file(sys.argv[1]) httpserver = tornado.httpserver.HTTPServer(Application(config)) PORT = config['port'] httpserver.listen(PORT) print("Server listening port {}".format(PORT)) tornado.ioloop.IOLoop.current().start()
def main(): tornado.options.parse_command_line() app = tornado.web.Application([("/", IndexHandler)]) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(options.port) tornado.ioloop.IOLoop.instance().start()
self.write(responseVals) self.finish() else: print('first request') print(responseCache) pass # todo: should probably validate stream names stream1 = self.get_query_argument('stream1') stream2 = self.get_query_argument('stream2') if stream1 and stream2: http_client = tornado.httpclient.AsyncHTTPClient() # if stream data is not in the cache, fetch next item if not responseCache.get(stream1): http_client.fetch(PELOTON_API_ENDPOINT+stream1, handle_request) if not responseCache.get(stream2): http_client.fetch(PELOTON_API_ENDPOINT+stream2, handle_request) else: self.send_error(400) self.finish if __name__ == "__main__": app = tornado.web.Application( handlers=[(r"/quiz/merge", MainHandler)], debug=True ) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(8888) tornado.ioloop.IOLoop.instance().start()
import tornado.web import tornado.httpserver import tornado.ioloop from handlers import IndexHandler from settings import Setting class Application(tornado.web.Application): def __init__(self): pivot = Setting() pivot.check_settings_file() handlers = [ (r'/', IndexHandler) ] settings = { 'debug': pivot.setting('DEBUG'), 'template_path': os.path.join(pivot.root, 'templates'), 'static_path': os.path.join(pivot.root, 'static'), 'candidate': pivot.candidate } tornado.web.Application.__init__(self, handlers, **settings) if __name__ == '__main__': httpserver = tornado.httpserver.HTTPServer(Application()) httpserver.listen(8010) tornado.ioloop.IOLoop.instance().start()
import tornado.web import tornado.ioloop import tornado.httpserver from urls import uri from conf import settings class App(tornado.web.Application): def __init__(self): super(App, self).__init__(uri, **settings.settings) if __name__ == "__main__": app = App() httpserver = tornado.httpserver.HTTPServer(app) #httpserver.listen(settings.port) httpserver.listen(9003) tornado.ioloop.IOLoop.instance().start()
'provided (--ssl-cert / --ssl-key\n') sys.exit(1) # Connect to database lg.info('Connecting to Redis database at {0}:{1!s}'.format(args.redis_host, args.redis_port)) database = cloaca.db.connect( host=args.redis_host, port=args.redis_port, prefix='') # prefix doesn't work with Lua scripts yet. ioloop = tornado.ioloop.IOLoop.current() ioloop.run_sync(lambda: database.select(args.redis_db)) # Start server lg.info('Starting Cloaca server on port {0}'.format(args.port)) app = make_app(database) settings = {} if not args.no_ssl: settings['ssl_options'] = { "certfile": os.path.abspath(args.ssl_cert), "keyfile": os.path.abspath(args.ssl_key), } httpserver = tornado.httpserver.HTTPServer(app, **settings) httpserver.listen(args.port) tornado.ioloop.IOLoop.current().start()
) self.database = database tornado.web.Application.__init__(self, handlers, **settings) class BaseHandler(tornado.web.RequestHandler): @property def db(self): return self.application.database class MainPageHandler(BaseHandler): def get(self): self.render('main_page.html') if __name__ == "__main__": if (len(sys.argv) != 2): print "error: missing config file" exit(0) config = load_config_file(sys.argv[1]) httpserver = tornado.httpserver.HTTPServer( Application( db.Database(config['database'], config['host'], config['user'], config['password']), config, )) httpserver.listen(int(config['port'])) print("Server listening port {}".format(config['port'])) tornado.ioloop.IOLoop.current().start()
sql = "INSERT INTO face_login (id, base64) VALUES ( %.2f , '%s')" data = (0, imgBase64) InsertTable(sql, data) self.redirect('/') class AjaxReqHandle(web.RequestHandler): def post(self, *args, **kwargs): sql = "SELECT id,base64 FROM face_login WHERE id = '%s' " data = (0) selectTable(sql, data) self.write('123') class SuccessHandle(web.RequestHandler): def get(self, *args, **kwargs): self.render('success.html') settings = { "static_path": os.path.join(os.path.dirname(__file__), "static") } #配置静态文件路径 application = web.Application([(r'/', MainPageHandle), (r'/register', RegistPageHandle), (r'/faceck', AjaxReqHandle), (r'/success', SuccessHandle)], **settings) if __name__ == '__main__': httpserver = httpserver.HTTPServer(application) httpserver.listen(8086) ioloop.IOLoop.current().start()
__author__ = 'levi' from tornado import web, httpserver, ioloop; from musicProject.functions import get_music_info_by_name; class MainPageHandler(web.RequestHandler): def get(self,*args,**kwargs): # self.write('欢迎来到音乐网站公开主页!') self.render('index.html'); class GetMusicInfoHandler(web.RequestHandler): def post(self, *args, **kwargs): query = self.get_argument('query') music_info = get_music_info_by_name(query) self.render('music.html',music=music_info) application=web.Application([ (r"/index", MainPageHandler), (r"/query", GetMusicInfoHandler), ]) if __name__ == '__main__': httpserver=httpserver.HTTPServer(application) httpserver.listen(8080) ioloop.IOLoop.current().start();
''' tornado框架 IOloop IO轮询模块 ''' import tornado.httpserver ''' tornado框架 http服务器模块 ''' class IndexHandler(tornado.web.RequestHandler): def get(self, *args, **kwargs): self.write("http server running") if __name__ == '__main__': app = tornado.web.Application([(r"/", IndexHandler)]) httpserver = tornado.httpserver.HTTPServer(app) httpserver.listen(8000) """ 这里启动了IOloop.current()实例,它会一直访问linux epoll linux epoll 管理socket的读写,有客户端连接时,创建socket 创建的socket可以进行IO读取操作 同时tornado.web会收到socket的数据 然后加载路由映射表 当请求地址是根路径的时候/找到IndexHanlder类 并执行get方法,返回一个字符串 """ tornado.ioloop.IOLoop.current().start()
def main(): options.parse_command_line() App = Application() httpserver = tornado.httpserver.HTTPServer(App) httpserver.listen(port=options.port) tornado.ioloop.IOLoop.instance().start()
debug=True, cookie_secret="7840GFhHSZC6xUl66a5EV3J4XNrdckv0ginaF5XY1jE=", login_url="/", ) tornado.web.Application.__init__(self, handlers, **settings) def make_app(): app = tornado.web.Application( handlers=[ (r'/', IndexHandler), (r'/signin', SigninHandler), (r'/user', UserHandler), ], settings=dict( template_path=os.path.join(os.path.dirname(__file__), "template"), static_path=os.path.join(os.path.dirname(__file__), "static"), debug=True, cookie_secret="7840GFhHSZC6xUl66a5EV3J4XNrdckv0ginaF5XY1jE=", login_url="/", )) return app if __name__ == "__main__": tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(Application()) print options.port httpserver.listen(options.port) tornado.ioloop.IOLoop.instance().start()
import handlers.ping import handlers.api log = logging.getLogger(__name__) class Application(tornado.web.Application): def __init__(self): app_handlers = [ ('/', handlers.api.APIHandler), ('/ping', handlers.ping.PingHandler), ] app_settings = { 'debug': os.environ.get('ENV') == 'dev' } super(Application, self).__init__(app_handlers, **app_settings) if __name__ == '__main__': tornado.options.define('port', default=9000) tornado.options.parse_command_line() port = tornado.options.options.port log.info('Listening on port %s' % port) httpserver = tornado.httpserver.HTTPServer(request_callback=Application(), xheaders=True) httpserver.listen(port, address='0.0.0.0') tornado.ioloop.IOLoop.instance().start()
def main(): tornado.options.parse_command_line() httpserver = tornado.httpserver.HTTPServer(Application()) httpserver.listen(options.port) tornado.ioloop.IOLoop.instance().start()
import tornado.ioloop import tornado.httpserver import config from application import Application if __name__ == '__main__': app=Application() httpserver=tornado.httpserver.HTTPServer(app) httpserver.listen(config.options['port']) tornado.ioloop.IOLoop.current().start()