24 from __future__
import with_statement
25 from builtins
import str
26 from builtins
import object
33 a lock-protected container for data that can be shared amongst threads. 35 This container holds data that is intended to be shared amongst multiple 36 threads. In order to update or (optionally) examine the data, one must 37 first aquire the lock associated with the container. 39 This container also behaves like a threading.Container, via its 40 wait(), notify(), and notifyAll() functions. Also like Condition, 41 acquire() is reentrant. 43 SharedData instances may be used with the with statement: 49 The with statement will acquire the lock and ensure that it is released 50 when its block is exited. 53 def __init__(self, needLockOnRead=True, data=None, cond=None):
55 create and initialize the shared data 56 @param needLockOnRead if true (default), acquiring the lock will 57 be needed when reading the data. This is recommended 58 if the data items are anything but primitive types; 59 otherwise, a compound data item (e.g. of type dict) 60 could be updated without acquiring a lock. 61 @param data a dictionary of data to initialize the container with. 62 This is done by calling initData(). Set this value to 63 False when calling from a subclass constructor; this 64 will allow any non-protected attributes to be set via 65 the subclass's constructor. If None is given (default), 66 it is assumed that all new attributes will be considered 68 @param cond Reuse this existing Condition instance to protect this 73 cond = threading.Condition()
86 if isinstance(data, dict):
99 if name ==
"_d" or not self.
_d or name
not in self.
_d:
100 return object.__getattribute__(self, name)
103 raise AttributeError(
"%s: lock required for read access" % name)
107 if name ==
"_d" or not self.
_d or name
in self.__dict__:
108 object.__setattr__(self, name, value)
112 raise AttributeError(
"%s: lock required for write access" % name)
114 self.
_d[name] = value
118 initialize the container with the data from a dictionary. 119 @param data a dictionary of data to initialize the container with. 120 Attributes will be added to this container with names 121 matching the given the dictionary's key names and 122 initialized to their corresponding values. The keys 123 cannot match an existing function (or internal attribute) 125 @throws ValueError if the dictionary has a key that conflicts with 126 an existing function or internal attribute name. 129 bad = set(data.keys()).intersection(set(self.__dict__.keys()))
131 raise ValueError(
"Names cause conflicts with functions or " +
132 "internal data: " + str(bad))
135 self.
_d[key] = data[key]
141 return [k
for k
in self.
_d if k !=
"__"]
def __setattr__(self, name, value)
def __init__(self, needLockOnRead=True, data=None, cond=None)
def __getattribute__(self, name)
def __exit__(self, exc_info)