Message264865
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. |
|
Date |
User |
Action |
Args |
2016-05-04 23:48:23 | rhettinger | set | recipients:
+ rhettinger, Sudharsan R |
2016-05-04 23:48:23 | rhettinger | set | messageid: <1462405703.78.0.0981202529077.issue26958@psf.upfronthosting.co.za> |
2016-05-04 23:48:23 | rhettinger | link | issue26958 messages |
2016-05-04 23:48:23 | rhettinger | create | |
|