This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Sudharsan R, rhettinger
Date 2016-05-04.23:48:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1462405703.78.0.0981202529077.issue26958@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-05-04 23:48:23rhettingersetrecipients: + rhettinger, Sudharsan R
2016-05-04 23:48:23rhettingersetmessageid: <1462405703.78.0.0981202529077.issue26958@psf.upfronthosting.co.za>
2016-05-04 23:48:23rhettingerlinkissue26958 messages
2016-05-04 23:48:23rhettingercreate