Movatterモバイル変換


[0]ホーム

URL:


bug with Queue in Python 1.5.2

Tim Peterstim.one at home.com
Fri Apr 20 17:58:25 EDT 2001


[Alexandre Fayolle]> I think I encountered a bug in Queue using python 1.5.2, and I was> wondering if it was still around in python 2.x.>> I have a Queue with infinite sizeNo you don't <wink>.> that sometimes raises QueueFull exceptions when I use put_nowait.>> The reason is that the fsema lock is acquired before the mutex lock,> and it is possible for instance with 2 threads to have the first one> take fsema and mutex, and then the second one trying to acquire fsema,> and failing immediately (because it's in nowait mode), which causes a> Full Queue exception.>> Is this still the case with later releases of Python?Yes, it is, although the docs may have changed in the meantime.  Here's therelevant bit from the 2.1 docs:exception Full    Exception raised when non-blocking put() (or put_nowait()) is    called on a Queue object which is full or locked.That is, Full doesn't mean *only* full.  If you're playing with non-blockingputs or gets, the reasonable presumption is that you want to regain controlASAP if the Queue can't satisfy your request immediately.  If the Queue islocked at the time of the call, your request can't be satisfied immediatelyfor that reason alone, and so the call returns ASAP but without doinganything (and raises an exception to let you *know* it didn't do anything).In your case, since your Queue is infinite, it doesn't make sense to use anon-blocking put, unless you *want* Queue to raise Full when it's locked(!):use plain .put() instead.  Then you'll never see Full.


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp