我有以下骷髅龙卷风计划:
class IS(BaseHandler):
@tornado.gen.coroutine
def get(self):
#render stuff
def post(self):
try:
# load Image
except RuntimeWarning:
# handle exception
class Application(tornado.web.Application):
def __init__(self):
# Current handlers
handlers = [
(r'/',IS),
]
# Settings dict for Application
settings = {
"template_path": "templates",
"static_path": "static"
}
tornado.web.Application.__init__(self,handlers,debug=True,**settings)
if __name__ =='__main__':
# is this the right place to set the warnings?
warnings.simplefilter('error', Image.DecompressionBombWarning)
app=Application()
server=tornado.httpserver.HTTPServer(app)
server.listen(7000)
tornado.ioloop.IOLoop.current().start()
我想知道警告的设置范围是什么?我是否必须在IS类中设置它?或者是我把它设置好的地方?或者它应该在应用程序 init 中?
答案 0 :(得分:2)
warnings.simplefilter
影响整个过程(当它不是从with warnings.catch_warnings()
块内部调用时),因此要全局控制警告,您只需在启动时调用它一次,就像您所做的那样。