Update synchronized decorator
Changes coordination.synchronized decorator to preserve decorated function signature. Change-Id: I0ea24312ec32d844e232a443723b4f065f96efcb
This commit is contained in:
parent
14899a9a8e
commit
70d9d187f9
@ -20,6 +20,7 @@ import random
|
||||
import threading
|
||||
import uuid
|
||||
|
||||
import decorator
|
||||
import eventlet
|
||||
from eventlet import tpool
|
||||
import itertools
|
||||
@ -275,13 +276,12 @@ def synchronized(lock_name, blocking=True, coordinator=None):
|
||||
Available field names are: decorated function parameters and
|
||||
`f_name` as a decorated function name.
|
||||
"""
|
||||
def wrap(f):
|
||||
@six.wraps(f)
|
||||
def wrapped(*a, **k):
|
||||
call_args = inspect.getcallargs(f, *a, **k)
|
||||
call_args['f_name'] = f.__name__
|
||||
lock = Lock(lock_name, call_args, coordinator)
|
||||
with lock(blocking):
|
||||
return f(*a, **k)
|
||||
return wrapped
|
||||
return wrap
|
||||
|
||||
@decorator.decorator
|
||||
def _synchronized(f, *a, **k):
|
||||
call_args = inspect.getcallargs(f, *a, **k)
|
||||
call_args['f_name'] = f.__name__
|
||||
lock = Lock(lock_name, call_args, coordinator)
|
||||
with lock(blocking):
|
||||
return f(*a, **k)
|
||||
return _synchronized
|
||||
|
@ -13,6 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import inspect
|
||||
|
||||
import mock
|
||||
import tooz.coordination
|
||||
import tooz.locking
|
||||
@ -134,3 +136,4 @@ class CoordinationTestCase(test.TestCase):
|
||||
bar.__getitem__.return_value = 8
|
||||
func(foo, bar)
|
||||
get_lock.assert_called_with('lock-func-7-8')
|
||||
self.assertEqual(['foo', 'bar'], inspect.getargspec(func)[0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user