Author JBernardo
Recipients JBernardo, neologix, pitrou, sbt
Date 2013-05-29.14:39:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1369838394.61.0.130348427836.issue18078@psf.upfronthosting.co.za>
In-reply-to
Content
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)

Bonus:
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.


----

Sample:

    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.
History
Date User Action Args
2013-05-29 14:39:54JBernardosetrecipients: + JBernardo, pitrou, neologix, sbt
2013-05-29 14:39:54JBernardosetmessageid: <1369838394.61.0.130348427836.issue18078@psf.upfronthosting.co.za>
2013-05-29 14:39:54JBernardolinkissue18078 messages
2013-05-29 14:39:54JBernardocreate