warnings.simplefilter('error', Image.DecompressionBombWarning) 的范围
Scope of warnings.simplefilter('error', Image.DecompressionBombWarning)
我有以下骨架龙卷风程序:
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 class 中设置它吗?还是我设置好的地方?还是应该在 Application init 中?
warnings.simplefilter
影响整个过程(当它不是从 with warnings.catch_warnings()
块内部调用时),因此要全局控制警告,您只需在启动时调用它一次,就像您已经完成。
我有以下骨架龙卷风程序:
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 class 中设置它吗?还是我设置好的地方?还是应该在 Application init 中?
warnings.simplefilter
影响整个过程(当它不是从 with warnings.catch_warnings()
块内部调用时),因此要全局控制警告,您只需在启动时调用它一次,就像您已经完成。