Lock
SyncLock
SyncLock(
cache: CacheProtocol,
key: Any,
*,
timeout: float = DEFAULT_LOCK_TIMEOUT,
expire: float | None = None,
tags: str | Iterable[str] | None = None
)
Bases: SyncLockProtocol
Lock implementation using spin-lock algorithm.
Assumes the key will not be evicted. Set the eviction policy to 'none' on the cache to guarantee the key is not evicted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CacheProtocol
|
Cache to use for lock. |
required |
|
Any
|
Key for lock. |
required |
|
float
|
Timeout for lock. |
DEFAULT_LOCK_TIMEOUT
|
|
float | None
|
Expiration time for lock. |
None
|
|
str | Iterable[str] | None
|
Tags for lock. |
None
|
Examples:
Source code in src/typed_diskcache/implement/sync/lock.py
acquire
Acquire lock using spin-lock algorithm.
Source code in src/typed_diskcache/implement/sync/lock.py
SyncRLock
SyncRLock(
cache: CacheProtocol,
key: Any,
*,
timeout: float = DEFAULT_LOCK_TIMEOUT,
expire: float | None = None,
tags: str | Iterable[str] | None = None
)
Bases: SyncLock
Re-entrant lock implementation using spin-lock algorithm.
Assumes the key will not be evicted. Set the eviction policy to 'none' on the cache to guarantee the key is not evicted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CacheProtocol
|
Cache to use for lock. |
required |
|
Any
|
Key for lock. |
required |
|
float
|
Timeout for lock. |
DEFAULT_LOCK_TIMEOUT
|
|
float | None
|
Expiration time for lock. |
None
|
|
str | Iterable[str] | None
|
Tags for lock. |
None
|
Examples:
Source code in src/typed_diskcache/implement/sync/lock.py
acquire
Acquire lock using spin-lock algorithm.
Source code in src/typed_diskcache/implement/sync/lock.py
release
Release lock by deleting key.
Source code in src/typed_diskcache/implement/sync/lock.py
AsyncLock
AsyncLock(
cache: CacheProtocol,
key: Any,
*,
timeout: float = DEFAULT_LOCK_TIMEOUT,
expire: float | None = None,
tags: str | Iterable[str] | None = None
)
Bases: AsyncLockProtocol
Lock implementation using spin-lock algorithm.
Warning
If the current Python interpreter is free-threading (without GIL),
using AsyncLock may lead to unexpected
behavior. Consider using SyncLock
instead in such cases.
Assumes the key will not be evicted. Set the eviction policy to 'none' on the cache to guarantee the key is not evicted.
Asynchronous version of SyncLock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CacheProtocol
|
Cache to use for lock. |
required |
|
Any
|
Key for lock. |
required |
|
float
|
Timeout for lock. |
DEFAULT_LOCK_TIMEOUT
|
|
float | None
|
Expiration time for lock. |
None
|
|
str | Iterable[str] | None
|
Tags for lock. |
None
|
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
Examples:
Source code in src/typed_diskcache/implement/sync/lock.py
acquire
async
Acquire lock using spin-lock algorithm.
Source code in src/typed_diskcache/implement/sync/lock.py
AsyncRLock
AsyncRLock(
cache: CacheProtocol,
key: Any,
*,
timeout: float = DEFAULT_LOCK_TIMEOUT,
expire: float | None = None,
tags: str | Iterable[str] | None = None
)
Bases: AsyncLock
Re-entrant lock implementation using spin-lock algorithm.
Warning
If the current Python interpreter is free-threading (without GIL),
using AsyncRLock may lead to unexpected
behavior. Consider using SyncRLock
instead in such cases.
Assumes the key will not be evicted. Set the eviction policy to 'none' on the cache to guarantee the key is not evicted.
Asynchronous version of SyncRLock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CacheProtocol
|
Cache to use for lock. |
required |
|
Any
|
Key for lock. |
required |
|
float
|
Timeout for lock. |
DEFAULT_LOCK_TIMEOUT
|
|
float | None
|
Expiration time for lock. |
None
|
|
str | Iterable[str] | None
|
Tags for lock. |
None
|
Warns:
| Type | Description |
|---|---|
RuntimeWarning
|
If the current Python interpreter is free-threading (without GIL),
using |
Examples:
Source code in src/typed_diskcache/implement/sync/lock.py
acquire
async
Acquire lock using spin-lock algorithm.
Source code in src/typed_diskcache/implement/sync/lock.py
release
async
Release lock by deleting key.
Release lock by decrementing count.