Tornado—接口调用时方法执行顺序

import tornado.web       # web服务
import tornado.ioloop    # I/O 时间循环
 
class MainHandler(tornado.web.RequestHandler):
    def initialize(self,name):
    	self.name = name
        print 'initialize方法执行'
        
    def prepare(self):
        print 'prepare方法执行'
    
    def set_default_headers(self):
        print 'set_default_headers方法执行'
        self.set_header("Access-Control-Allow-Origin", "*")
        self.set_header("Access-Control-Allow-Headers", "x-requested-with")
        self.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
        
    # 响应以get方式发起的请求
    def get(self, *args, **kwargs):
    	print 'get方法执行'
        self.write("hello world!")
        
    # 响应以post方式发起的请求
    def post(self, *args, **kwargs):
        print 'post方法执行'
        self.write(json.dumps({"status": "success", "data": task_list}))
        
    def on_finish(self):
        print 'on_finish方法执行'
    
    def write_error(self, status_code, **kwargs):
        print 'write_error方法执行'
        super().write_error(status_code, **kwargs)
 
app = tornado.web.Application([
        (r"/index", MainHandler, dict(name="name")),
    ])
 
if __name__ == "__main__":
    app.listen(8000)  # 监听端口
    # tornado.ioloop.IOLoop.current().start()
    tornado.ioloop.IOLoop.instance().start()  # 开始事件

https://blog.csdn.net/qq_20042935/article/details/100325953

https://www.cnblogs.com/qianzhengkai/p/11348023.html

你可能感兴趣的:(Tornado—接口调用时方法执行顺序)