登録されたATEXIT関数でエラートレースバックを取得します
質問
私のプロセスがシャットダウンされた原因となったエラーを記録しようとしていますが、traceback.print_tb
とtraceback.print_exc
は、上げられたエラーが何であるかに気づかないようではありません。
つまり、「DivisionByZero.ect。」ではなく、なぜ次の印刷「なし\ N」を印刷しますか。(編集:.. ..そして、exit_fn内から発生/処理中のエラーにアクセスするにはどうすればよいですか?)
import traceback, atexit
def exit_fn():
print 'exiting'
if traceback.format_exc().startswith('None'):
print 'why is this None?'
atexit.register(exit_fn)
x = 1/0
. 解決
I believe that, by the time your routine has been called, the exception has already been 'handled' (at least when I run your code, I see a traceback even if I remove your call to print one), so that there is none to be formatted at that point.
所属していません StackOverflow