| 10 | |
| 11 | |
| 12 | def 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 | |
| 28 | def _probe_read_write_lock(lock_file: str, mode: Literal["read", "write"], acquired: Synchronized[bool]) -> None: |