(
lock_file: str,
mode: Literal["read", "write"],
acquired_event: EventType,
release_event: EventType | None = None,
timeout: float = -1,
blocking: bool = True,
ready_event: EventType | None = None,
contending_event: EventType | None = None,
)
| 33 | |
| 34 | |
| 35 | def acquire_lock( |
| 36 | lock_file: str, |
| 37 | mode: Literal["read", "write"], |
| 38 | acquired_event: EventType, |
| 39 | release_event: EventType | None = None, |
| 40 | timeout: float = -1, |
| 41 | blocking: bool = True, |
| 42 | ready_event: EventType | None = None, |
| 43 | contending_event: EventType | None = None, |
| 44 | ) -> None: |
| 45 | if ready_event: |
| 46 | ready_event.wait(timeout=PROCESS_DEADLINE) |
| 47 | |
| 48 | lock = ReadWriteLock(lock_file, timeout=timeout, blocking=blocking) |
| 49 | if contending_event: |
| 50 | contending_event.set() # interpreter start-up is over, so a caller can time the contention itself |
| 51 | with getattr(lock, f"{mode}_lock")(): |
| 52 | acquired_event.set() |
| 53 | if release_event: |
| 54 | release_event.wait(timeout=PROCESS_DEADLINE) |
| 55 | |
| 56 | |
| 57 | @contextmanager |
nothing calls this directly
no test coverage detected