Is the weakref.ref callback is called deterministically?

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Jun 13 17:19:11 CEST 2002


janeaustine50 at hotmail.com (Jane Austine) wrote in 
news:ba1e306f.0206130451.795085d6 at posting.google.com:

> Even though the index i does not change, it loops till the
> result is not None. Seemingly it depends on the weakref.ref
> callback to remove dead weakrefs.
> 
> However, the while loop wouldn't be needed if the callback
> was called right after the last reference to the object
> was "del"ed.
> 
Have you considered what would happen in a multithreaded program if the 
weak reference became invalid after it was retrieved from the dictionary or 
list, but before it was converted to a strong reference? There may be other 
reasons, but you need loops here to avoid the race condition.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list