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)
| 254 | |
| 255 | @contextmanager |
| 256 | def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]: |
| 257 | """ |
| 258 | Context manager that acquires and releases an exclusive write lock. |
| 259 | |
| 260 | Falls back to instance defaults for *timeout* and *blocking* when ``None``. |
| 261 | |
| 262 | :param timeout: maximum wait time in seconds, or ``None`` to use the instance default |
| 263 | :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default |
| 264 | |
| 265 | :raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread |
| 266 | :raises Timeout: if the lock cannot be acquired within *timeout* seconds |
| 267 | |
| 268 | """ |
| 269 | self.acquire_write(timeout, blocking=blocking) |
| 270 | try: |
| 271 | yield |
| 272 | finally: |
| 273 | self.release() |
| 274 | |
| 275 | def acquire_read(self, timeout: float | None = None, *, blocking: bool | None = None) -> AcquireReturnProxy: |
| 276 | """ |