server.py
1.21 KB
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
# coding: utf-8
import os
import tornado.ioloop
import tornado.autoreload
import tornado.web
from tornado.options import define, options, parse_command_line
import settings
from log import init_log
def init_settings():
# 加载环境配置项
define('port', default=8080, type=int, help=u'监听端口')
define("log_dir", default='run', type=str, help=u'日志目录')
define('profile', default='local', type=str, help=u'运行配置')
parse_command_line()
init_log(options.log_dir)
return options
def start_application():
from url import urls
log_dir = os.path.join(os.path.dirname(__file__), 'run')
application_settings = {
'handlers': urls,
'debug': settings.DEBUG,
'template_path': os.path.join(os.path.dirname(__file__), 'templates'),
'static_path': os.path.join(os.path.dirname(__file__), 'static'),
}
application = tornado.web.Application(**application_settings)
print 'server on port %s' % settings.PORT
print 'server log on %s' % log_dir
application.listen(settings.PORT)
io_loop = tornado.ioloop.IOLoop.instance()
io_loop.start()
def run():
init_settings()
start_application()
if __name__ == '__main__':
run()