基于Tornado的web,数据的预先加载

用python得Tornado框架做web Demo,数据的预加载终于搞定了,不用每一次post都要load一次数据了,加快了执行速度。

def load_data():
  
        return *


class Application(tornado.web.Application):

    def __init__(self):
        handles = [
            (r'/', IndexHandler),
            (r'/result', ResultPageHandler),
        ]
        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,handles,**settings)
        s=clock()
        self.feadata = load_data()
        e=clock()
        print (e-s)
        print "loading data done!"

def main():
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()


你可能感兴趣的:(程序调试配置)