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

Method read_lock

src/filelock/_async_read_write.py:112–134  ·  view source on GitHub ↗

Async 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``, rai

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

Source from the content-addressed store, hash-verified

110
111 @asynccontextmanager
112 async def read_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> AsyncGenerator[None]:
113 """
114 Async context manager that acquires and releases a shared read lock.
115
116 Falls back to instance defaults for *timeout* and *blocking* when ``None``.
117
118 :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
119 :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
120
121 """
122 if timeout is None:
123 timeout = self._lock.timeout
124 if blocking is None:
125 blocking = self._lock.blocking
126 await self.acquire_read(timeout, blocking=blocking)
127 body_error: BaseException | None = None
128 try:
129 yield
130 except BaseException as error:
131 body_error = error
132 raise
133 finally:
134 await self._release_in_context(body_error)
135
136 @asynccontextmanager
137 async def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> AsyncGenerator[None]:

Calls 2

acquire_readMethod · 0.95
_release_in_contextMethod · 0.95