Async 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``
(self, timeout: float | None = None, *, blocking: bool | None = None)
| 135 | |
| 136 | @asynccontextmanager |
| 137 | async def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> AsyncGenerator[None]: |
| 138 | """ |
| 139 | Async context manager that acquires and releases an exclusive write lock. |
| 140 | |
| 141 | Falls back to instance defaults for *timeout* and *blocking* when ``None``. |
| 142 | |
| 143 | :param timeout: maximum wait time in seconds, or ``None`` to use the instance default |
| 144 | :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default |
| 145 | |
| 146 | """ |
| 147 | if timeout is None: |
| 148 | timeout = self._lock.timeout |
| 149 | if blocking is None: |
| 150 | blocking = self._lock.blocking |
| 151 | await self.acquire_write(timeout, blocking=blocking) |
| 152 | body_error: BaseException | None = None |
| 153 | try: |
| 154 | yield |
| 155 | except BaseException as error: |
| 156 | body_error = error |
| 157 | raise |
| 158 | finally: |
| 159 | await self._release_in_context(body_error) |
| 160 | |
| 161 | async def _release_in_context(self, body_error: BaseException | None) -> None: |
| 162 | try: |