Use of threading.Condition class

Aahz Maruch aahz at panix.com
Thu Jan 4 11:05:47 EST 2001


In article <mailman.978611884.20920.python-list at python.org>,
 <vonWedel at lfpt.rwth-aachen.de> wrote:
>
>I'm trying to pass data between threads A and B. A notifies B to produce 
>something 
>and now I want the reference to the produced instance back in thread A. 
>The documentation for threading.Condition proposes something like
>
>     # Consume one item
>     cv.acquire()
>     while not an_item_is_available():
>         cv.wait()
>     get_an_available_item()
>     cv.release()
>
>for the consumer side. I don't understand the while loop around
>the cv.wait() statement -- wouldn't cv.wait() block anyway until 
>cv.notify() has been called in the other thread?

According to the book I've been using, you do this because the condition
might get triggered when an item is not available (most likely because
you're sharing the condition across multiple consumer threads).
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"This is Usenet.  We're all masturbating in public places."  -DH



More information about the Python-list mailing list