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

Method read_lock

src/filelock/_read_write.py:369–387  ·  view source on GitHub ↗

Context manager that acquires and releases a shared read 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``, raise :cl

(self, timeout: float | None = None, *, blocking: bool | None = None)

Source from the content-addressed store, hash-verified

367
368 @contextmanager
369 def read_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:
370 """
371 Context manager that acquires and releases a shared read lock.
372
373 Falls back to instance defaults for *timeout* and *blocking* when ``None``.
374
375 :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
376 :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
377
378 """
379 if timeout is None:
380 timeout = self.timeout
381 if blocking is None:
382 blocking = self.blocking
383 self.acquire_read(timeout, blocking=blocking)
384 try:
385 yield
386 finally:
387 self.release()
388
389 @contextmanager
390 def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:

Calls 2

acquire_readMethod · 0.95
releaseMethod · 0.95