MCPcopy Create free account
hub / github.com/tox-dev/filelock / write_lock

Method write_lock

src/filelock/_soft_rw/_sync.py:244–261  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 """

Callers 2

_workerFunction · 0.95

Calls 2

acquire_writeMethod · 0.95
releaseMethod · 0.95

Tested by 2

_workerFunction · 0.76