| 351 | parent_pid = os.getpid() |
| 352 | |
| 353 | class BlockingLock(BaseFileLock): |
| 354 | def __init__(self, lock_file: str, *, is_singleton: bool = False) -> None: |
| 355 | if os.getpid() == parent_pid: |
| 356 | entered.set() |
| 357 | release.wait(timeout=5) |
| 358 | super().__init__(lock_file, thread_local=False, is_singleton=is_singleton) |
| 359 | |
| 360 | @override |
| 361 | def _acquire(self) -> None: |
| 362 | self._context.lock_file_fd = os.open(self.lock_file, os.O_CREAT | os.O_RDWR, 0o600) |
| 363 | |
| 364 | @override |
| 365 | def _release(self) -> None: |
| 366 | os.close(self._context.lock_file_fd if self._context.lock_file_fd is not None else -1) |
| 367 | self._context.lock_file_fd = None |
| 368 | |
| 369 | worker = threading.Thread(target=BlockingLock, args=(str(tmp_path / "mutex.lock"),), kwargs={"is_singleton": True}) |
| 370 | worker.start() |