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 threading
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import decorator
|
||||||
import eventlet
|
import eventlet
|
||||||
from eventlet import tpool
|
from eventlet import tpool
|
||||||
import itertools
|
import itertools
|
||||||
@ -275,13 +276,12 @@ def synchronized(lock_name, blocking=True, coordinator=None):
|
|||||||
Available field names are: decorated function parameters and
|
Available field names are: decorated function parameters and
|
||||||
`f_name` as a decorated function name.
|
`f_name` as a decorated function name.
|
||||||
"""
|
"""
|
||||||
def wrap(f):
|
|
||||||
@six.wraps(f)
|
@decorator.decorator
|
||||||
def wrapped(*a, **k):
|
def _synchronized(f, *a, **k):
|
||||||
call_args = inspect.getcallargs(f, *a, **k)
|
call_args = inspect.getcallargs(f, *a, **k)
|
||||||
call_args['f_name'] = f.__name__
|
call_args['f_name'] = f.__name__
|
||||||
lock = Lock(lock_name, call_args, coordinator)
|
lock = Lock(lock_name, call_args, coordinator)
|
||||||
with lock(blocking):
|
with lock(blocking):
|
||||||
return f(*a, **k)
|
return f(*a, **k)
|
||||||
return wrapped
|
return _synchronized
|
||||||
return wrap
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import inspect
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import tooz.coordination
|
import tooz.coordination
|
||||||
import tooz.locking
|
import tooz.locking
|
||||||
@ -134,3 +136,4 @@ class CoordinationTestCase(test.TestCase):
|
|||||||
bar.__getitem__.return_value = 8
|
bar.__getitem__.return_value = 8
|
||||||
func(foo, bar)
|
func(foo, bar)
|
||||||
get_lock.assert_called_with('lock-func-7-8')
|
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