Author JBernardo
Recipients JBernardo, neologix, pitrou, sbt
Date 2013-05-29.14:39:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I did what @Richard Oudkerk said and created the "wait_for_any" classmethod for the Condition class.

Other Changes:

 - I had to refactor "wait" and "wait_for" to be specializations of "wait_for_any".
 - try...except on "notify" because the inner lock might have been released by other condition.
 - Added two helper functions "_remove_waiter" and "_wait" (the part of the old wait function to re-acquire the inner lock)

To simplify the use, I added a "from_condition" constructor to create a new condition using the same lock as an existing one.
That way, you don't need to record the lock someplace else before creating a new Condition for the same lock.

* The current tests pass.

* Missing: new tests and docs.



    lock = Lock()
    cond1 = Condition(lock)
    cond2 = Condition(lock)
    cond3 = Condition.from_condition(cond1)

    with lock:
        Condition.wait_for_any({cond1: foo, cond2: bar})
        Condition.wait_for_any([cond1, cond2, cond3]) # no predicates
                                                      # used on "wait"
    with cond2: # same thing
        Condition.wait_for_any({cond3: foo})


PS: the patch text is messy because of refactoring and some lines were moved. It is easy to read when applied.
Date User Action Args
2013-05-29 14:39:54JBernardosetrecipients: + JBernardo, pitrou, neologix, sbt
2013-05-29 14:39:54JBernardosetmessageid: <>
2013-05-29 14:39:54JBernardolinkissue18078 messages
2013-05-29 14:39:54JBernardocreate