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