iPython 노트북에서 올바른 디버그 방법은 무엇입니까?
아시다시피 %debug magic
한 셀 내에서 디버그 할 수 있습니다.
그러나 여러 셀에서 함수 호출이 있습니다.
예를 들어
In[1]: def fun1(a)
def fun2(b)
# I want to set a breakpoint for the following line #
return do_some_thing_about(b)
return fun2(a)
In[2]: import multiprocessing as mp
pool=mp.Pool(processes=2)
results=pool.map(fun1, 1.0)
pool.close()
pool.join
내가 시도한 것 :
%debug
cell-1의 첫 번째 줄에 설정하려고했습니다 . 그러나 cell-2를 실행하기 전에 즉시 디버그 모드로 들어갑니다.%debug
코드 바로 앞에 줄 을 추가하려고 했습니다return do_some_thing_about(b)
. 그러나 코드는 영원히 실행되며 멈추지 않습니다.
ipython 노트북 내에서 중단 점을 설정하는 올바른 방법은 무엇입니까?
ipdb 사용
통해 설치
pip install ipdb
용법:
In[1]: def fun1(a):
def fun2(a):
import ipdb; ipdb.set_trace() # debugging starts here
return do_some_thing_about(b)
return fun2(a)
In[2]: fun1(1)
라인 단위로 실행 n하고 함수로 단계적으로 사용 s하고 디버깅 프롬프트 사용을 종료하려면 c.
사용 가능한 명령의 전체 목록을 보려면 https://appletree.or.kr/quick_reference_cards/Python/Python%20Debugger%20Cheatsheet.pdf
ipdb
jupyter 내부에서 다음을 사용할 수 있습니다 .
from IPython.core.debugger import Tracer; Tracer()()
편집 : 위의 기능은 IPython 5.1부터 사용되지 않습니다. 이것이 새로운 접근법입니다.
from IPython.core.debugger import set_trace
set_trace()
중단 점이 필요한 곳에 추가하십시오 . 입력 help
에 대한 ipdb
입력 필드가 나타나면 명령.
반환 기능은 def 기능 (주 기능)에 따라 하나의 탭을 제공해야합니다. 그리고 사용
%%debug
대신에
%debug
전체 셀뿐만 아니라 라인을 디버그합니다. 희망, 아마도 이것이 당신을 도울 것입니다.
언제든지 셀에 추가 할 수 있습니다.
import pdb; pdb.set_trace()
디버거가 해당 라인에서 중지됩니다. 예를 들면 다음과 같습니다.
In[1]: def fun1(a):
def fun2(a):
import pdb; pdb.set_trace() # debugging starts here
return fun2(a)
In[2]: fun1(1)
그냥 입력 import pdb
jupyter 노트북에, 다음이 사용 쪽지를 디버그. 매우 편리합니다.
c
--> continue, s
--> step, b 12
--> set break point at line 12 and so on.
Some useful links: Python Official Document on pdb, Python pdb debugger examples for better understanding how to use the debugger commands.
The %pdb
magic command is good to use as well. Just say %pdb on
and subsequently the pdb
debugger will run on all exceptions, no matter how deep in the call stack. Very handy.
If you have a particular line that you want to debug, just raise an exception there (often you already are!) or use the %debug
magic command that other folks have been suggesting.
In Python 3.7 you can use breakpoint() function. Just enter
breakpoint()
wherever you would like runtime to stop and from there you can use the same pdb commands (r, c, n, ...) or evaluate your variables.
After you get an error, in the next cell just run %debug
and that's it.
I just discovered PixieDebugger. Even thought I have not yet had the time to test it, it really seems the most similar way to debug the way we're used in ipython with ipdb
It also has an "evaluate" tab
참고URL : https://stackoverflow.com/questions/32409629/what-is-the-right-way-to-debug-in-ipython-notebook
'Programming' 카테고리의 다른 글
AWS Command Line Tools의 자격 증명을 테스트하는 방법 (0) | 2020.08.05 |
---|---|
Intellij Idea에서 사용되지 않는 모든 클래스를 어떻게 찾습니까? (0) | 2020.08.05 |
스위치 속도 대 (0) | 2020.08.05 |
.aspx와 .ashx MAIN의 차이점 (0) | 2020.08.05 |
간헐적 인 log4net RollingFileAppender 잠금 파일 문제 (0) | 2020.08.05 |