문제

프로세스가 종료 될 수 있지만 traceback.print_tbtraceback.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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top