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

Function assert_read_write_lock_state

tests/read_write_helpers.py:12–25  ·  view source on GitHub ↗
(lock_file: str, mode: Literal["read", "write"], *, available: bool)

Source from the content-addressed store, hash-verified

10
11
12def assert_read_write_lock_state(lock_file: str, mode: Literal["read", "write"], *, available: bool) -> None:
13 context = multiprocessing.get_context("spawn")
14 acquired = context.Value("b", False)
15 probe = context.Process(target=_probe_read_write_lock, args=(lock_file, mode, acquired))
16 probe.start()
17 try:
18 probe.join(timeout=5)
19 assert not probe.is_alive(), "read-write lock probe did not exit"
20 assert (probe.exitcode, acquired.value) == (0, available)
21 finally:
22 if probe.is_alive(): # pragma: no cover - cleanup for a hung child after the assertion fails
23 probe.terminate()
24 probe.join(timeout=5)
25 probe.close()
26
27
28def _probe_read_write_lock(lock_file: str, mode: Literal["read", "write"], acquired: Synchronized[bool]) -> None:

Calls 2

joinMethod · 0.80
closeMethod · 0.45