channel.py: fix to use coros.Channel

This commit is contained in:
Denis Bilenko
2009-06-26 09:17:51 +07:00
parent 8be282a60d
commit 831656b796

View File

@@ -1,16 +1,23 @@
from eventlet import coros from eventlet import coros
class channel(coros.queue): class channel(coros.Channel):
def __init__(self):
coros.queue.__init__(self, 0)
def receive(self): def receive(self):
return self.wait() return self.wait()
@property @property
def balance(self): def balance(self):
return self.sem.balance return len(self.items) - len(self._waiters)
import warnings import warnings
warnings.warn("channel is deprecated; use coros.queue(0) which behaves the same", DeprecationWarning, stacklevel=2) warnings.warn("channel.py is deprecated by coros.Channel", DeprecationWarning, stacklevel=2)
if __name__ == '__main__':
from eventlet import proc, api
c = channel()
proc.spawn(c.send, 'X')
proc.spawn(c.send, 'Y')
assert c.wait() == 'X', c
assert c.wait() == 'Y', c
assert api.with_timeout(1, c.wait, timeout_value='hello') == 'hello', c