From 13395dc48cb203d5aa25df69dcaa1a9ebc5c4db4 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 16 Jun 2009 15:35:21 +0700 Subject: [PATCH] coros.event: remove cancel() method it's broken and nobody on the list admitted using it --- eventlet/coros.py | 45 ----------------------------------------- greentest/coros_test.py | 13 ------------ 2 files changed, 58 deletions(-) diff --git a/eventlet/coros.py b/eventlet/coros.py index 614148a..eff3c1a 100644 --- a/eventlet/coros.py +++ b/eventlet/coros.py @@ -154,51 +154,6 @@ class event(object): api.getcurrent().throw(*self._exc) return self._result - def cancel(self, waiter): - """Raise an exception into a coroutine which called - wait() an this event instead of returning a value - from wait. Sends the eventlet.coros.Cancelled - exception - - waiter: The greenlet (greenlet.getcurrent()) of the - coroutine to cancel - - >>> from eventlet import coros, api - >>> evt = coros.event() - >>> def wait_on(): - ... try: - ... print "received " + evt.wait() - ... except coros.Cancelled, c: - ... print "Cancelled" - ... - >>> waiter = api.spawn(wait_on) - - The cancel call works on coroutines that are in the wait() call. - - >>> api.sleep(0) # enter the wait() - >>> evt.cancel(waiter) - >>> api.sleep(0) # receive the exception - Cancelled - - The cancel is invisible to coroutines that call wait() after cancel() - is called. This is different from send()'s behavior, where the result - is passed to any waiter regardless of the ordering of the calls. - - >>> waiter = api.spawn(wait_on) - >>> api.sleep(0) - - Cancels have no effect on the ability to send() to the event. - - >>> evt.send('stuff') - >>> api.sleep(0) - received stuff - """ - if waiter in self._waiters: - del self._waiters[waiter] - # XXX This does not check that waiter still waits when throw actually happens - # XXX and therefore is broken (see how send() deals with this) - api.get_hub().schedule_call(0, waiter.throw, Cancelled()) - def send(self, result=None, exc=None): """Makes arrangements for the waiters to be woken with the result and then returns immediately to the parent. diff --git a/greentest/coros_test.py b/greentest/coros_test.py index f2a807a..3121301 100644 --- a/greentest/coros_test.py +++ b/greentest/coros_test.py @@ -60,19 +60,6 @@ class TestEvent(TestCase): self.assertEqual(len(results), count) -# commented out, not fixed because it's unclear what event.cancel(waiter) should do -# (docstring and the code say different things) and because cancel() as implemented now -# has a bug -# def test_cancel(self): -# evt = coros.event() -# # close over the current coro so we can cancel it explicitly -# current = api.getcurrent() -# def cancel_event(): -# evt.cancel(current) -# api.spawn(cancel_event) -# -# self.assertRaises(coros.Cancelled, evt.wait) - def test_reset(self): evt = coros.event()