Locking access to all data members



I have a class with a lot of attributes whose objects are accessed
from multiple threads. I would like to synchronize the access to all
the attributes, i.e. acquire a lock, return the value, release the
lock (in a finally clause).

Is there a way to do that without turning each attribute into a
property and manually wrapping each property with the locking code?

How about classes bound with SQLAlchemy? Is it possible to do that for
those too?

Example of a class I would like to wrap:

class Job(object):
def __init__(self, itemType):
self.id = self.idSequence
self.itemType = itemType
self.status = "waiting"
self.createDate = None
self.hostName = None
self.progress = 0
self.items = []

.



Relevant Pages