Raymond Hettinger added the comment:

The reliability issue for qsize(), empty(), and full() has nothing to do with 
their implementations.  The problem is that any information obtained by those 
methods is potentially out-of-date by the time you try to use it (the LBYL 
problem).  This is why multi-threaded programmers prefer (try: os.remove(fn) 
except OSError: pass) over (if os.path.exists(fn): os.remove(fn)) where the 
latter has an intrinsic race condition regardless of the implementation of 
os.path.exists().

One other note, self.not_full uses self.mutex internally.  There is only one 
underlying lock for the whole queue implementation.

Lastly, despite not having an underscore prefix in its name, q.not_full() is 
not part of the public API.  Your "it hangs" example is part of the reason why 
;-)

In general, don't use full and empty tests to decide whether or not to do a put 
or get.  Instead, just try the put or get directly and catch the exception if 
queue turns out to be full or empty.

----------
resolution:  -> not a bug
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26958>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to