-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
58 lines (48 loc) · 1.88 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
import sys
import tornado.ioloop
import tornado.httpserver
import tornado.web
from tornado.options import options, define, parse_command_line
import os
import lib.homehandler
import Right.Handler
from UI.CommonModules import StatusCodeModule, RadioModule, CheckboxModule
from lib.urlmap import urlmap
from lib.Route import session
class Application(tornado.web.Application):
def __init__(self):
handlers = tuple(urlmap.handlers)
settings = dict(
AppTitle='Example for easyui admin',
static_path=os.path.join(os.path.dirname(__file__), "static"),
template_path=os.path.join(os.path.dirname(__file__), "templates"),
debug=True,
xsrf_cookies=True,
autoescape=None,
login_url='/login',
cookie_secret='61oETzKXQAGaYdkL5gEmGEJJFuYh7EQnp2XdTP1o/V==',
ui_modules={'StatusCodeModule': StatusCodeModule,
'RadioModule': RadioModule,
'CheckboxModule': CheckboxModule
},
)
self.db = session
tornado.locale.load_translations('i18n')
tornado.ioloop.PeriodicCallback(self._ping_db, 4 * 3600 * 1000).start()
tornado.web.Application.__init__(self, handlers, **settings)
def _ping_db(self):
self.db.execute('show variables')
self.db.close_all()
define('port', type=int, default=4000)
def main():
parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
reload(sys)
sys.setdefaultencoding('utf-8')
main()
# python -m cProfile -o profile_data.pyprof script_to_profile.py
# gprof2dot.py -f pstats profile_data.pyprof | dot -Tpng -o output.png