Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@property
def locked(self) -> bool:
return self._lock.read_locked
async def acquire(self) -> None:
await self._lock.acquire_read()
def release(self) -> None:
self._lock.release_read()
def __repr__(self) -> str:
status = 'locked' if self._lock._r_state > 0 else 'unlocked'
return ''.format(status)
class _WriterLock(_ContextManagerMixin):
def __init__(self, lock: _RWLockCore):
self._lock = lock
@property
def locked(self) -> bool:
return self._lock.write_locked
async def acquire(self) -> None:
await self._lock.acquire_write()
def release(self) -> None:
self._lock.release_write()
def __repr__(self) -> str:
status = 'locked' if self._lock._w_state > 0 else 'unlocked'
# We have no use for the "as ..." clause in the with
# statement for locks.
return None
async def __aexit__(self, *args: List[Any]) -> None:
self.release()
async def acquire(self) -> None:
raise NotImplementedError # pragma: no cover
def release(self) -> None:
raise NotImplementedError # pragma: no cover
# Lock objects to access the _RWLockCore in reader or writer mode
class _ReaderLock(_ContextManagerMixin):
def __init__(self, lock: _RWLockCore) -> None:
self._lock = lock
@property
def locked(self) -> bool:
return self._lock.read_locked
async def acquire(self) -> None:
await self._lock.acquire_read()
def release(self) -> None:
self._lock.release_read()
def __repr__(self) -> str:
status = 'locked' if self._lock._r_state > 0 else 'unlocked'