2016-05-28 11 views
1

私は、次のスケルトン竜巻プログラムがあります。範囲(「エラー」、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クラス内で設定する必要がありますか?それとも私はそれを設定したのですか?または、アプリケーション内にある必要があります init?

答えて

2

warnings.simplefilterは、プロセス全体(with warnings.catch_warnings()ブロック内から呼び出されていない場合)に影響します。したがって、警告をグローバルに制御するには、起動時に一度だけ呼び出す必要があります。

+0

いつもベンに感謝します。私はあなたが失ったたくさんの飲み物をあなたに借りています:P –