2017-09-14 1 views
0

Jupyter 노트북의 파이썬 코드에서 추적 코드를 숨기려고하므로 오류 유형과 메시지 만 표시됩니다.Jupyter에서 어떻게 추적 표시를 억제합니까?

This answersys.tracebacklimit = 0을 제안하지만 다음 준 시도해도 : 또한 사용자 정의 기능을 sys.excepthook를 교체 제안하지만, 역 추적이 계속 표시했다 대답

 
ERROR:root:Internal Python error in the inspect module. 
Below is the traceback from this internal error. 

ERROR:root:Internal Python error in the inspect module. 
Below is the traceback from this internal error. 

Traceback (most recent call last): 
AssertionError 
Traceback (most recent call last): 
AssertionError 

.

어떻게 추적 표시를 숨길 수 있습니까?

답변

0

두 가지 방법으로 IPython을 monkeypatching하는 방법을 발견했습니다.

# 1. 예외 유형 및 메시지 만 출력되지만 출력 영역에서는 빨간색으로 강조 표시됩니다.

from __future__ import print_function # for python 2 compatibility 
import sys 
ipython = get_ipython() 

def exception_handler(exception_type, exception, traceback): 
    print("%s: %s" % (exception_type.__name__, exception), file=sys.stderr) 

ipython._showtraceback = exception_handler 

# 2. 예외를 출력하고 예외 코드를 색상 코드로 출력합니다 (Jupyter가 정상적으로 수행하지만 추적 코드는 제외).

import sys 
ipython = get_ipython() 

def hide_traceback(exc_tuple=None, filename=None, tb_offset=None, 
        exception_only=False, running_compiled_code=False): 
    etype, value, tb = sys.exc_info() 
    return ipython._showtraceback(etype, value, ipython.InteractiveTB.get_exception_only(etype, value)) 

ipython.showtraceback = hide_traceback 
관련 문제