Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file itself may be deleted automatically, the behavior is platform-specific. :param force: If true, the lock counter is ignored and the lock is released in every case.
(self, force: bool = False)
| 562 | time.sleep(poll_interval) |
| 563 | |
| 564 | def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002 |
| 565 | """ |
| 566 | Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file |
| 567 | itself may be deleted automatically, the behavior is platform-specific. |
| 568 | |
| 569 | :param force: If true, the lock counter is ignored and the lock is released in every case. |
| 570 | |
| 571 | """ |
| 572 | if self.is_locked: |
| 573 | self._context.lock_counter -= 1 |
| 574 | |
| 575 | if self._context.lock_counter == 0 or force: |
| 576 | lock_id, lock_filename = id(self), self.lock_file |
| 577 | |
| 578 | _LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename) |
| 579 | self._release() |
| 580 | self._context.lock_counter = 0 |
| 581 | _registry.held.pop(_canonical(lock_filename), None) |
| 582 | _LOGGER.debug("Lock %s released on %s", lock_id, lock_filename) |
| 583 | |
| 584 | def __enter__(self) -> Self: |
| 585 | """ |