-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Flavio Preto schrieb: > Hi, > > I have a doubt. Supose that i have the minimun class below: > > class db: > def __init__(self): > self.db = {} > def read(self, key): > return self.db[key] > def write(self, key, value): > self.db[key] = value > > > and an object of this class is shared among some threads. Is it possible > that in a read, the method return a value that is not an old or a new value? > In other words, is it possible that a 'read' return (due to a 'write' at the > same time by another thread) an invalid value that was never supposed to be > there? > > Thanks, > Flavio Preto > >
Make the class thread safe by using Lock or RLock ... that will save you a lot of trouble. Your limited example might or might not work, but once your class gets more complex you will most likely run into serious problems. Greetings Nils -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGzHsizvGJy8WEGTcRAgN1AJ42cM1P/NW7Ei3F5ViSsmTcKDvCIgCeIUGG GD7DAb3f+Lmcav663F+wkQg= =kJ0G -----END PGP SIGNATURE----- -- http://mail.python.org/mailman/listinfo/python-list