prefect.locking.protocol
LockManager
Bases: Protocol
Source code in src/prefect/locking/protocol.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
aacquire_lock(key, holder, acquire_timeout=None, hold_timeout=None)
async
Acquire a lock for a transaction record with the given key. Will block other actors from updating this transaction record until the lock is released.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier for the transaction record. |
required |
holder
|
str
|
Unique identifier for the holder of the lock. |
required |
acquire_timeout
|
Optional[float]
|
Max number of seconds to wait for the record to become available if it is locked while attempting to acquire a lock. Pass 0 to attempt to acquire a lock without waiting. Blocks indefinitely by default. |
None
|
hold_timeout
|
Optional[float]
|
Max number of seconds to hold the lock for. Holds the lock indefinitely by default. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the lock was successfully acquired; False otherwise. |
Source code in src/prefect/locking/protocol.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
acquire_lock(key, holder, acquire_timeout=None, hold_timeout=None)
Acquire a lock for a transaction record with the given key. Will block other actors from updating this transaction record until the lock is released.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier for the transaction record. |
required |
holder
|
str
|
Unique identifier for the holder of the lock. |
required |
acquire_timeout
|
Optional[float]
|
Max number of seconds to wait for the record to become available if it is locked while attempting to acquire a lock. Pass 0 to attempt to acquire a lock without waiting. Blocks indefinitely by default. |
None
|
hold_timeout
|
Optional[float]
|
Max number of seconds to hold the lock for. Holds the lock indefinitely by default. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the lock was successfully acquired; False otherwise. |
Source code in src/prefect/locking/protocol.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
await_for_lock(key, timeout=None)
async
Wait for the corresponding transaction record to become free.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier for the transaction record. |
required |
timeout
|
Optional[float]
|
Maximum time to wait. None means to wait indefinitely. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the lock becomes free within the timeout; False otherwise. |
Source code in src/prefect/locking/protocol.py
110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
is_lock_holder(key, holder)
Check if the current holder is the lock holder for the transaction record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier for the transaction record. |
required |
holder
|
str
|
Unique identifier for the holder of the lock. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the current holder is the lock holder; False otherwise. |
Source code in src/prefect/locking/protocol.py
83 84 85 86 87 88 89 90 91 92 93 94 |
|
is_locked(key)
Simple check to see if the corresponding record is currently locked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier for the transaction record. |
required |
Returns:
Type | Description |
---|---|
bool
|
True is the record is locked; False otherwise. |
Source code in src/prefect/locking/protocol.py
71 72 73 74 75 76 77 78 79 80 81 |
|
release_lock(key, holder)
Releases the lock on the corresponding transaction record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier for the transaction record. |
required |
holder
|
str
|
Unique identifier for the holder of the lock. Must match the holder provided when acquiring the lock. |
required |
Source code in src/prefect/locking/protocol.py
60 61 62 63 64 65 66 67 68 69 |
|
wait_for_lock(key, timeout=None)
Wait for the corresponding transaction record to become free.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
Unique identifier for the transaction record. |
required |
timeout
|
Optional[float]
|
Maximum time to wait. None means to wait indefinitely. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the lock becomes free within the timeout; False otherwise. |
Source code in src/prefect/locking/protocol.py
96 97 98 99 100 101 102 103 104 105 106 107 108 |
|