CZ_OpenSpice/app.py

77 lines
3.6 KiB
Python
Raw Normal View History

2021-01-20 12:01:46 +00:00
import tornado.ioloop #开启循环,让服务一直等待请求的到来
import tornado.web #web服务基本功能都封装在此模块中
import tornado.options #从命令行中读取设置
from tornado.options import define,options #导入包
2021-01-22 12:09:14 +00:00
from handler import main, auth, spice
2021-01-20 12:01:46 +00:00
# import _thread,threading
2021-01-22 12:09:14 +00:00
# from spice import app_spice
2021-01-20 12:01:46 +00:00
2021-01-26 12:47:02 +00:00
define('port',default='9000',help='Listening port',type=int) #定义如何接受传进来的东西
2021-01-20 12:01:46 +00:00
class Application(tornado.web.Application): #引入Application类重写方法这样做的好处在于可以自定义添加另一些功能
def __init__(self):
handlers = [
2021-03-30 09:47:52 +00:00
(r'/',main.Open_Index_Zh_Handler),
(r'/index_test',main.IndexHandler),
(r'/index',main.Index_Zh_Handler),
(r'/index_Zh',main.Index_Zh_Handler),
(r'/index_En',main.Index_En_Handler),
(r'/open_index_Zh',main.Open_Index_Zh_Handler),
(r'/open_index_En',main.Open_Index_En_Handler),
2021-01-20 12:01:46 +00:00
(r'/login',auth.LoginHandler),
(r'/logout',auth.LogoutHandler),
(r'/register',auth.RegisterHandler),
2021-02-08 08:05:18 +00:00
(r'/schematic',spice.Schematic_Handler),
2021-01-26 12:47:02 +00:00
(r'/spice1',spice.Spice_1_Handler),
2021-01-22 12:09:14 +00:00
(r'/spice2',spice.Spice_2_Handler),
(r'/spice3',spice.Spice_3_Handler),
(r'/spice4',spice.Spice_4_Handler),
(r'/test',main.TestHandler),
2021-02-08 08:05:18 +00:00
(r'/spice',spice.SpiceHandler),
(r'/simulation',spice.SimulationHandler),
2021-03-20 07:45:00 +00:00
(r'/getsiminfo',spice.SimulationInfoRequest_Handler),
2021-01-20 12:01:46 +00:00
]
settings = dict(
debug = False, #调试模式,修改后自动重启服务,不需要自动重启,生产情况下切勿开启,安全性
2021-03-30 09:47:52 +00:00
# autoescape = None,
2021-01-20 12:01:46 +00:00
template_path='template', #模板文件目录,想要Tornado能够正确的找到html文件需要在 Application 中指定文件的位置
static_path='static', #静态文件目录,可用于用于访问js,css,图片之类的添加此配置之后tornado就能自己找到静态文件
login_url='/login', #没有登录则跳转至此
cookie_secret='1q2w3e4r', # 加密cookie的字符串
pycket={ #固定写法packet用于保存用户登录信息
'engine': 'redis',
'storage': {
'host': 'localhost',
'port': 6379,
'db_sessions': 5,
'db_notifications': 11,
'max_connections': 2 ** 33,
},
'cookie': {
# 'expires_secends': 1*60
'expires_days': 1,
'max_age': 100
}
}
)
2021-02-08 08:05:18 +00:00
static_hash_cache=False
2021-01-20 12:01:46 +00:00
super(Application,self).__init__(handlers,**settings) #用super方法将父类的init方法重新执行一遍然后将handlers和settings传进去完成初始化
app = Application() #实例化
if __name__ == '__main__': #当.py文件被直接运行时代码块将被运行当.py文件以模块形式被导入时代码块不被运行。
# 开启 bokeh 服务
2021-01-22 12:09:14 +00:00
# app_spice.app_spice_begin()
2021-01-20 12:01:46 +00:00
tornado.options.parse_command_line()
app.listen(options.port) ##如果一个与define语句中同名的设置在命令行中被给出那么它将成为全局的options的一个属性 即 options.port 相当于define的url的port
print("Server start on port {}".format(str(options.port))) #提示服务启动占用端口
tornado.ioloop.IOLoop.current().start() #执行ioloop
2021-01-26 12:47:02 +00:00