등록 된 atexit 기능에서 오류 추적을 얻는 것
문제
프로세스가 종료 될 수 있지만 traceback.print_tb
및 traceback.print_exc
가 발생한 오류가 무엇인지 실현하는 것 같지 않은 오류를 기록하려고합니다.
다른 말로하면, 'divisionbyzero .. 등 대신 다음과 같은 인쇄'없음 \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