X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=eventlet%2Feventlet%2Fcoros.py;fp=eventlet%2Feventlet%2Fcoros.py;h=0000000000000000000000000000000000000000;hb=358bd9258c2b6d2ee74de4dfd07a5123107abad4;hp=431e6f0576759238759f2b2662e06528dd6bfabc;hpb=376ff3bfe7071cc0793184a378c4e74508fb0d97;p=packages%2Ftrusty%2Fpython-eventlet.git diff --git a/eventlet/eventlet/coros.py b/eventlet/eventlet/coros.py deleted file mode 100644 index 431e6f0..0000000 --- a/eventlet/eventlet/coros.py +++ /dev/null @@ -1,61 +0,0 @@ -from __future__ import print_function - -from eventlet import event as _event - - -class metaphore(object): - """This is sort of an inverse semaphore: a counter that starts at 0 and - waits only if nonzero. It's used to implement a "wait for all" scenario. - - >>> from eventlet import coros, spawn_n - >>> count = coros.metaphore() - >>> count.wait() - >>> def decrementer(count, id): - ... print("{0} decrementing".format(id)) - ... count.dec() - ... - >>> _ = spawn_n(decrementer, count, 'A') - >>> _ = spawn_n(decrementer, count, 'B') - >>> count.inc(2) - >>> count.wait() - A decrementing - B decrementing - """ - - def __init__(self): - self.counter = 0 - self.event = _event.Event() - # send() right away, else we'd wait on the default 0 count! - self.event.send() - - def inc(self, by=1): - """Increment our counter. If this transitions the counter from zero to - nonzero, make any subsequent :meth:`wait` call wait. - """ - assert by > 0 - self.counter += by - if self.counter == by: - # If we just incremented self.counter by 'by', and the new count - # equals 'by', then the old value of self.counter was 0. - # Transitioning from 0 to a nonzero value means wait() must - # actually wait. - self.event.reset() - - def dec(self, by=1): - """Decrement our counter. If this transitions the counter from nonzero - to zero, a current or subsequent wait() call need no longer wait. - """ - assert by > 0 - self.counter -= by - if self.counter <= 0: - # Don't leave self.counter < 0, that will screw things up in - # future calls. - self.counter = 0 - # Transitioning from nonzero to 0 means wait() need no longer wait. - self.event.send() - - def wait(self): - """Suspend the caller only if our count is nonzero. In that case, - resume the caller once the count decrements to zero again. - """ - self.event.wait()