@@ -23,8 +23,8 @@ class LockedResourceError(RuntimeError):
23
23
Exception raised when an operation is attempted on a locked resource.
24
24
25
25
Attributes:
26
- ` type` -- name of the locked resource's type
27
- `id` -- ID of the locked resource
26
+ type (str): Name of the locked resource's type
27
+ id (typing.Hashable): ID of the locked resource
28
28
"""
29
29
30
30
def __init__ (self , resource_type : str , resource_id : Hashable ):
@@ -76,19 +76,20 @@ def lock(
76
76
"""
77
77
Turn the decorated coroutine function into a mutually exclusive operation on a `resource_id`.
78
78
79
- If `wait` is True, wait until the lock becomes available. Otherwise, if any other mutually
80
- exclusive function currently holds the lock for a resource, do not run the decorated function
81
- and return None.
82
-
83
- If `raise_error` is True, raise `LockedResourceError` if the lock cannot be acquired.
84
-
85
- `namespace` is an identifier used to prevent collisions among resource IDs.
86
-
87
- `resource_id` identifies a resource on which to perform a mutually exclusive operation.
88
- It may also be a callable or awaitable which will return the resource ID given an ordered
89
- mapping of the parameters' names to arguments' values.
90
-
91
79
If decorating a command, this decorator must go before (below) the `command` decorator.
80
+
81
+ Arguments:
82
+ namespace (typing.Hashable): An identifier used to prevent collisions among resource IDs.
83
+ resource_id: identifies a resource on which to perform a mutually exclusive operation.
84
+ It may also be a callable or awaitable which will return the resource ID given an ordered
85
+ mapping of the parameters' names to arguments' values.
86
+ raise_error (bool): If True, raise `LockedResourceError` if the lock cannot be acquired.
87
+ wait (bool): If True, wait until the lock becomes available. Otherwise, if any other mutually
88
+ exclusive function currently holds the lock for a resource, do not run the decorated function
89
+ and return None.
90
+
91
+ Raises:
92
+ :exc:`LockedResourceError`: If the lock can't be acquired and `raise_error` is set to True.
92
93
"""
93
94
def decorator (func : types .FunctionType ) -> types .FunctionType :
94
95
name = func .__name__
@@ -144,8 +145,10 @@ def lock_arg(
144
145
"""
145
146
Apply the `lock` decorator using the value of the arg at the given name/position as the ID.
146
147
147
- `func` is an optional callable or awaitable which will return the ID given the argument value.
148
148
See `lock` docs for more information.
149
+
150
+ Arguments:
151
+ func: An optional callable or awaitable which will return the ID given the argument value.
149
152
"""
150
153
decorator_func = partial (lock , namespace , raise_error = raise_error , wait = wait )
151
154
return function .get_arg_value_wrapper (decorator_func , name_or_pos , func )
0 commit comments