티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
Starting python debugger automatically on error
오류 발생 시 Python 디버거를 자동으로 시작하기
문제 내용
This is a question I have wondered about for quite some time, yet I have never found a suitable solution. If I run a script and I come across, let's say an IndexError, python prints the line, location and quick description of the error and exits. Is it possible to automatically start pdb when an error is encountered? I am not against having an extra import statement at the top of the file, nor a few extra lines of code.
이것은 내가 꽤 오랫동안 궁금해했던 질문이지만, 나는 결코 적절한 해결책을 찾지 못했다. 내가 스크립트를 실행하고 우연히 발견하면, IndexError라고 하자, python은 오류의 줄, 위치 및 빠른 설명을 출력하고 종료한다. 오류가 발생하면 pdb를 자동으로 시작할 수 있습니까? 나는 파일의 맨 위에 추가 import 문을 두는 것이나 코드의 몇 줄을 추가하는 것에 반대하지 않는다.
높은 점수를 받은 Solution
python -m pdb -c continue myscript.py
If you don't provide the -c continue
flag then you'll need to enter 'c' (for Continue) when execution begins. Then it will run to the error point and give you control there. As mentioned by eqzx, this flag is a new addition in python 3.2 so entering 'c' is required for earlier Python versions (see https://docs.python.org/3/library/pdb.html).
-c continue 플래그를 제공하지 않으면 실행이 시작될 때 'c'(계속)를 입력해야 합니다. 그런 다음 오류 지점까지 실행하여 해당 지점을 제어할 수 있습니다. eqzx가 언급한 바와 같이, 이 플래그는 파이썬 3.2의 새로운 추가이므로 이전 버전의 파이썬에서는 'c'를 입력해야 합니다(https://docs.python.org/3/library/pdb.html) 참조).
가장 최근 달린 Solution
If you are using ipython
, after launching type %pdb
ipython을 사용하는 경우 시작 후 %pdb 유형
In [1]: %pdb
Automatic pdb calling has been turned ON
출처 : https://stackoverflow.com/questions/242485/starting-python-debugger-automatically-on-error
'개발 > 파이썬' 카테고리의 다른 글
OSX 10.6에서 파이썬 및 장고와 함께 MySQLdb를 사용하는 방법은? (0) | 2022.11.27 |
---|---|
ImportError: libGL.so.1: 공유 개체 파일을 열 수 없습니다. 해당 파일 또는 디렉토리가 없습니다. (0) | 2022.11.27 |
clang error: unknown argument: '-mno-session-madd'(패키지 설치 실패) (0) | 2022.11.27 |
PyLint "Unable to import" 오류 - PYTHATH를 어떻게 설정합니까? (0) | 2022.11.27 |
파이썬 로깅의 시간 형식을 어떻게 사용자 지정합니까? (0) | 2022.11.26 |