mutex — mutex 모듈¶
mutex 모듈은 인터럽트 서비스 루틴과 메인 스레드에 의한 동시 접근으로부터 코드의 임계 구역이나 공유 데이터를 보호하기 위한 상호 배제(mutual-exclusion) 프리미티브를 제공합니다.
락 획득과 해제는 컨텍스트 관리자(with 문)를 통해 수행되며, 뮤텍스가 사용 가능해질 때까지 블록됩니다. 논블로킹 Mutex.test() 메서드도 제공됩니다.
예시:
from mutex import Mutex
mtx = Mutex()
# Acquire for a critical section (blocks if already held).
with mtx:
# ... protected code, e.g. shared buffer access ...
pass
# Or try without blocking.
if mtx.test():
try:
# ... protected code ...
pass
finally:
mtx.release()
class Mutex – 뮤텍스 객체¶
예외¶
- exception mutex.MutexException¶
OSError의 서브클래스입니다. 뮤텍스가 이미 잠금 해제된 상태일 때Mutex.release에 의해 발생합니다.