On Sep 22, 2006, at 1:08 PM, Jesus Cea wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > David Binger wrote: >> Here is a variation of the solution you suggested for >> just holding a plain dict of weakrefs. Please review it. > > Good. > >> + def __setitem__(self, key, value): >> + self.mapping[key] = KeyedRef(value, self.remove, key) > > What if that key was previously deleted and it is in "self.dead"?. You > add a new reference know, but it will vanish when we process > "self.dead". My original code has the same issue. If you do multiple > statements there, you probably have race-conditions when > multithreading. > > Studying the python "set" API, I think you can do a "set.discard()" > atomically even if the key doesn't exist. If you FIRST make sure that > self.dead is updated, that code would be safe. Adding a self.dead.discard(key) before the self.mapping[key] = line seems like a good idea. > > But then you have the issue in the "self.dead" clearing, were you > could > extract a key to delete and, before deleting it, other thread could > recreate the reference. Then you delete the reference, but the > object is > still out there. I think self.dead clearing needs to happen when other threads are excluded from touching the ObjectDictionary, and I think your application meets that condition by putting locks around Connection code. I'm not sure we need ObjectDictionary to be safe for other multi-threaded situations, but it would be okay with me if we made it so, as long as I can understand it. > > > These potential race-conditions would be nonexistant in current Durus > usage, nevertheless. > > I will try-out your code in my machines. Thanks.