Locking access to all data members

G

gooli

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 = []
 
D

Diez B. Roggisch

gooli said:
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 = []

You can use a metaclass or decorators to put the locking code in place
for all methods. I'm not sure though if that interferes with SQLAlchemy.


Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top