파이썬[Python]: sys - breakpointhook 함수

파이썬(Phthon): sys 모듈 - breakpointhook 함수(function)


/// 설명

내장함수 breakpoint()에 의해 호출되는 hook함수입니다. 기본값으로 pdb 디버거를 사용하지만 다른 디버거를 사용할 수 있습니다.
이 함수의 시그니쳐(signature)는 어떤 함수를 호출하느냐에 달려있습니다. 예를 들어 기본값으로 연결(binding)되어 있는 pdb.set_trace()는 인자를 사용하지 않을 수도 있지만, 다른 함수와 연결할 경우에는 필요할 수 있습니다. 내장함수 breakpoint()의 인자를 그대로 전달하며, breakpointhook()이 돌려주는 값은 breakpoint()에 전달됩니다.

환경변수 PYTHONBREAKPOINT
1. '0' : no-op
2. not set or empty string : calls pdb.set_trace()
3. set callable function() : calls callable function
(e.g. os.environ['PYTHONBREAKPOINT'] = 'foo.bar.baz' : import foo.bar and calls foo.bar.baz()) using 파이썬의 dotted-import nomenclature

만약 sys.breakpointhook()이 오버라이드(PYTHONBREAKPOINT를 사용하지 않게끔) 된다면, PYTHONBREAKPOINT를 확인하지 않습니다.

※ 형식
sys.breakpointhook()

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import sys
 
test_int1 = 10
test_int2 = -10
 
test_binary1 = bin(test_int1)
test_binary2 = bin(test_int2)
 
# os.environ['PYTHONBREAKPOINT'] = 'foo.bar.baz'
# sys.breakpointhook()  # Imports foo.bar and calls foo.bar.baz()
sys.breakpointhook()
print('Python Binary:', test_binary1)
print('Python Binary:', test_binary2)
print('-' * 25)
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수