def __setitem__(self, attr, val): if type(val) is dict: val = ThreadsafeDict(val) self.lock() try: dict.__setitem__(self, attr, val) finally: self.unlock()