Context manager that acquires and releases an exclusive write lock. Falls back to instance defaults for *timeout* and *blocking* when ``None``. :param timeout: maximum wait time in seconds, or ``None`` to use the instance default :param blocking: if ``False``, rais
(self, timeout: float | None = None, *, blocking: bool | None = None)
| 353 | |
| 354 | @contextmanager |
| 355 | def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]: |
| 356 | """ |
| 357 | Context manager that acquires and releases an exclusive write lock. |
| 358 | |
| 359 | Falls back to instance defaults for *timeout* and *blocking* when ``None``. |
| 360 | |
| 361 | :param timeout: maximum wait time in seconds, or ``None`` to use the instance default |
| 362 | :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default |
| 363 | |
| 364 | """ |
| 365 | if timeout is None: |
| 366 | timeout = self.timeout |
| 367 | if blocking is None: |
| 368 | blocking = self.blocking |
| 369 | self.acquire_write(timeout, blocking=blocking) |
| 370 | try: |
| 371 | yield |
| 372 | finally: |
| 373 | self.release() |
| 374 | |
| 375 | def close(self) -> None: |
| 376 | """ |