New submission from Juan Javier:
I think it will be useful to have a decorator like this one on the threading
module:
def synchronized(func):
"""A decorator to make a function execution synchronized.
Examples:
@synchronized
def foo():
pass
class Foo:
def __init__(self):
self.__syncdata = None
@property
def syncdata(self):
return self.__syncdata
@syncdata.setter
@synchronized
def syncdata(self, value):
self.__syncdata = value
"""
if not hasattr(func, "__lock"):
func.__lock = threading.Lock()
def _synchronized(*args, **kwds):
with func.__lock:
func(*args, **kwds)
_synchronized.__doc__ = func.__doc__
return _synchronized
What do you think?
----------
components: Library (Lib)
messages: 168071
nosy: jjdominguezm
priority: normal
severity: normal
status: open
title: synchronized decorator for the threading module
type: enhancement
versions: Python 3.4
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue15634>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com