MCPcopy Create free account
hub / github.com/tox-dev/filelock / acquire_lock

Function acquire_lock

tests/sqlite/process_support.py:35–54  ·  view source on GitHub ↗
(
    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,
)

Source from the content-addressed store, hash-verified

33
34
35def 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

Callers

nothing calls this directly

Calls 2

ReadWriteLockClass · 0.90
waitMethod · 0.80

Tested by

no test coverage detected