아래 링크 참고: https://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess
How to attach debugger to a python subproccess?
I need to debug a child process spawned by multiprocessing.Process(). The pdb degugger seems to be unaware of forking and unable to attach to already running processes. Are there any smarter python
stackoverflow.com
import sys
import pdb
class ForkedPdb(pdb.Pdb):
"""A Pdb subclass that may be used
from a forked multiprocessing child
"""
def interaction(self, *args, **kwargs):
_stdin = sys.stdin
try:
sys.stdin = open('/dev/stdin')
pdb.Pdb.interaction(self, *args, **kwargs)
finally:
sys.stdin = _stdin
상단 클래스를 정의해준 후, 원하는 디버깅 위치에 아래와 같은 코드로 호출
ForkedPdb().set_trace()

동일하게 pdb가 작동하는 것을 확인할 수 있다
'사소한 Tip . 오류 해결법 > python' 카테고리의 다른 글
[python/pdf2image] pdf 에서 페이지별 image 추출하기 (0) | 2022.11.23 |
---|---|
[python] list 요소 2개씩 묶기 (0) | 2022.11.21 |
[python/itertools] dictionary 갯수로 잘라내기(index slicing) (0) | 2022.08.25 |
[python] 파이썬 하위 디렉토리/파일 출력 / glob, os.walk / extract sub-directory , files (0) | 2022.08.23 |
[python] Ignore warning message/ 파이썬 경고 메시지 안 보이게 하기(무시하기) (1) | 2022.08.23 |
아래 링크 참고: https://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess
How to attach debugger to a python subproccess?
I need to debug a child process spawned by multiprocessing.Process(). The pdb degugger seems to be unaware of forking and unable to attach to already running processes. Are there any smarter python
stackoverflow.com
import sys
import pdb
class ForkedPdb(pdb.Pdb):
"""A Pdb subclass that may be used
from a forked multiprocessing child
"""
def interaction(self, *args, **kwargs):
_stdin = sys.stdin
try:
sys.stdin = open('/dev/stdin')
pdb.Pdb.interaction(self, *args, **kwargs)
finally:
sys.stdin = _stdin
상단 클래스를 정의해준 후, 원하는 디버깅 위치에 아래와 같은 코드로 호출
ForkedPdb().set_trace()

동일하게 pdb가 작동하는 것을 확인할 수 있다
'사소한 Tip . 오류 해결법 > python' 카테고리의 다른 글
[python/pdf2image] pdf 에서 페이지별 image 추출하기 (0) | 2022.11.23 |
---|---|
[python] list 요소 2개씩 묶기 (0) | 2022.11.21 |
[python/itertools] dictionary 갯수로 잘라내기(index slicing) (0) | 2022.08.25 |
[python] 파이썬 하위 디렉토리/파일 출력 / glob, os.walk / extract sub-directory , files (0) | 2022.08.23 |
[python] Ignore warning message/ 파이썬 경고 메시지 안 보이게 하기(무시하기) (1) | 2022.08.23 |