Re: Thread-safety of dict

2007-06-01 Thread Raymond Hettinger
On May 31, 9:12 pm, "Adam Olsen" <[EMAIL PROTECTED]> wrote: > It seems to be a commonly held belief that basic dict operations (get, > set, del) are atomic. They are atomic so long as the key does not have a custom __hash__, __eq__, or __cmp__ method which can trigger arbitrary Python code. With

Re: Thread-safety of dict

2007-06-01 Thread Rhamphoryncus
On Jun 1, 3:51 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > "Adam Olsen" <[EMAIL PROTECTED]> wrote: > > So there you have it: if you're using a dict with custom classes (or > > anything other than str) across multiple threads, and without locking > > it, it's possible (though presumably extremely

Re: Thread-safety of dict

2007-06-01 Thread Adam Olsen
On 6/1/07, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > So there you have it: if you're using a dict with custom classes (or > > anything other than str) across multiple threads, and without locking > > it, it's possible (though presumably extremely rare) for a lookup to > > fail even through t

Re: Thread-safety of dict

2007-06-01 Thread Duncan Booth
"Adam Olsen" <[EMAIL PROTECTED]> wrote: > So there you have it: if you're using a dict with custom classes (or > anything other than str) across multiple threads, and without locking > it, it's possible (though presumably extremely rare) for a lookup to > fail even through the key was there the en

Re: Thread-safety of dict

2007-06-01 Thread Martin v. Löwis
> So there you have it: if you're using a dict with custom classes (or > anything other than str) across multiple threads, and without locking > it, it's possible (though presumably extremely rare) for a lookup to > fail even through the key was there the entire time. That could be fixed by adding

Thread-safety of dict

2007-05-31 Thread Adam Olsen
It seems to be a commonly held belief that basic dict operations (get, set, del) are atomic. However, since I know searching the hash table is a multistep process, I thought I'd check it out for sure. First, my assumption is that one thread is attempting to get a single key, while other threads a