diff options
| author | Numerigraphe - Lionel Sausin <ls@numerigraphe.fr> | 2010-11-12 15:10:41 +0100 |
|---|---|---|
| committer | Numerigraphe - Lionel Sausin <ls@numerigraphe.fr> | 2010-11-12 15:10:41 +0100 |
| commit | 182cf2b196da0d1f55ddfdcff62058b423e1bbc0 (patch) | |
| tree | 779b50e2e54b1624ba669b4a3f56bb6407c08d49 /bin/tools/func.py | |
| parent | e013734045bbaae906748a8026455bac6786568e (diff) | |
| parent | cc0d270bab0d0b7862430c3e527f7edc02d1d587 (diff) | |
[MERGE] sync with the trunk
bzr revid: ls@numerigraphe.fr-20101112141041-19kpvr7pzxqankqo
Diffstat (limited to 'bin/tools/func.py')
| -rw-r--r-- | bin/tools/func.py | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/bin/tools/func.py b/bin/tools/func.py index 3168f5e6935..8cedf6715fd 100644 --- a/bin/tools/func.py +++ b/bin/tools/func.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). +# Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -15,17 +16,17 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## -__all__ = ['partial', 'wraps', 'update_wrapper'] +__all__ = ['partial', 'wraps', 'update_wrapper', 'synchronized'] try: from functools import partial, wraps, update_wrapper except ImportError: # The functools module doesn't exist in python < 2.5 - # Code taken from python 2.5 + # Code taken from python 2.5 # http://svn.python.org/view/python/tags/r254/Lib/functools.py?view=markup def partial(fun, *args, **kwargs): @@ -76,3 +77,19 @@ except ImportError: return partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated) + + +def synchronized(lock_attr='_lock'): + def decorator(func): + @wraps(func) + def wrapper(self, *args, **kwargs): + lock = getattr(self, lock_attr) + try: + lock.acquire() + return func(self, *args, **kwargs) + finally: + lock.release() + return wrapper + return decorator + + |
