Queue.Queue-like class without the busy-wait

Peter Hansen peter at engcorp.com
Thu Mar 24 19:32:46 EST 2005


Paul L. Du Bois wrote:
> Has anyone written a Queue.Queue replacement that avoids busy-waiting?
> It doesn't matter if it uses os-specific APIs (eg
> WaitForMultipleObjects).  I did some googling around and haven't found
> anything so far.
> 
> Because I know someone will ask: no, the busy-waiting hasn't been a
> problem in my app.  I'm just interested in reading the code.

I don't believe the term "busy-wait" applies here.
Busy-waiting is (in my experience) where you run in
tight loops without releasing the CPU, consuming all
CPU time available.

I'm fairly certain that while Queue (and other things
that wait in Python) does have a loop, you'll find that
it's not a busy-waiting loop and you definitely don't
get 100% CPU usage during the wait.  It goes to sleep
for increasingly large periods of time while waiting,
if the code in threading._Condition is any indication.

-Peter



More information about the Python-list mailing list