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

  • Re: How to not synchronize on an object already locked ?
    ... > to continue doing usefull instead of waiting. ... > simply waiting on the lock, by checking some condition on the object. ... Then you need only synchronize on the ...
    (comp.lang.java.programmer)
  • Re: Multithreaded GC!
    ... will share a heap across multiple threads, ... with "synchronize their allocations" though. ... synchronized using a lock. ...
    (microsoft.public.dotnet.languages.csharp)
  • when multiple threads are waiting on a mutex, which one will acquire the lock first?
    ... It often happens that multiple threads are waiting on a mutex, ... My question is, when the thread that held the mutex release it, is it ... a thread that is blocked on a mutex later can acquire the lock earlier. ...
    (comp.programming.threads)
  • Re: Suggestion for review: a taxonomy of thread safety
    ... > as regards their behavior when run in multiple threads, ... > lock ... for example you have an array of objects and you want to implement the ... from every entry of the array and fills it into a caller ...
    (comp.programming)
  • Re: Suggestion for review: a taxonomy of thread safety
    ... >> as regards their behavior when run in multiple threads, ... marked but only in s stateful class. ... > Not even a mutex (lock) can save you there. ... > for example you have an array of objects and you want to implement the ...
    (comp.programming)