Multithreading and Queue

Jeffrey Barish jeff_barish at earthlink.net
Tue Apr 25 15:27:32 EDT 2006


Several methods in Queue.Queue have warnings in their doc strings that they
are not reliable (e.g., qsize).  I note that the code in all these methods
is bracketed with lock acquire/release.  These locks are intended to
protect the enclosed code from collisions with other threads.  I am
wondering whether I understand correctly that the reason these methods are
still not reliable is that from the point where a thread calls qsize (for
example) to the point in Queue where a thread acquires a lock there is a
bunch of code, none of which is protected by a lock, (and moreover there is
another bunch of code between the point where a thread releases a lock and
then actually returns to the calling program) and so despite the locks in
Queue it is still possible for values to change before a thread acts on
them.
-- 
Jeffrey Barish




More information about the Python-list mailing list