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:49–70  ·  view source on GitHub ↗
(lock_file: str, mode: Literal["read", "write"], *, available: bool)

Source from the content-addressed store, hash-verified

47
48
49def assert_read_write_lock_state(lock_file: str, mode: Literal["read", "write"], *, available: bool) -> None:
50 context = multiprocessing.get_context("spawn")
51 # Pipes avoid GraalPy's multiprocessing semaphore failures.
52 receiving, sending = context.Pipe(duplex=False)
53 probe = context.Process(target=_probe_read_write_lock, args=(lock_file, mode, sending))
54 probe.start()
55 sending.close()
56 try:
57 # Spawn imports and coverage shutdown need separate budgets from the lock operation.
58 assert receiving.poll(timeout=10), "read-write lock probe did not start"
59 receiving.recv_bytes()
60 assert receiving.poll(timeout=5), "read-write lock probe did not finish"
61 acquired: Final[bytes] = receiving.recv_bytes()
62 probe.join(timeout=10)
63 assert not probe.is_alive(), "read-write lock probe did not exit"
64 assert (probe.exitcode, acquired) == (0, bytes([available]))
65 finally:
66 if probe.is_alive(): # pragma: no cover - cleanup for a hung child after the assertion fails
67 probe.terminate()
68 probe.join(timeout=5)
69 probe.close()
70 receiving.close()
71
72
73def _probe_read_write_lock(lock_file: str, mode: Literal["read", "write"], sending: Connection) -> None:

Calls 2

joinMethod · 0.80
closeMethod · 0.45