diff --git a/eventlet/pools.py b/eventlet/pools.py index 0ddbd1d..18ee6f3 100644 --- a/eventlet/pools.py +++ b/eventlet/pools.py @@ -274,7 +274,9 @@ class CoroutinePool(Pool): def _main_loop(self, sender): """ Private, infinite loop run by a pooled coroutine. """ try: - while True: + # not really a loop anymore because we want the greenlet + # to die so all its timers get canceled + if True: recvd = sender.wait() # Delete the sender's result here because the very # first event through the loop is referenced by @@ -285,21 +287,14 @@ class CoroutinePool(Pool): # tests. sender._result = coros.NOT_USED - sender = coros.event() (evt, func, args, kw) = recvd self._safe_apply(evt, func, args, kw) - #api.get_hub().cancel_timers(api.getcurrent()) # Likewise, delete these variables or else they will # be referenced by this frame until replaced by the # next recvd, which may or may not be a long time from # now. del evt, func, args, kw, recvd - - self.put(sender) finally: - # if we get here, something broke badly, and all we can really - # do is try to keep the pool from leaking items. - # Shouldn't even try to print the exception. self.put(self.create()) def _safe_apply(self, evt, func, args, kw): diff --git a/greentest/pools_test.py b/greentest/pools_test.py index 3b70560..d81c8d1 100644 --- a/greentest/pools_test.py +++ b/greentest/pools_test.py @@ -284,16 +284,16 @@ class TestCoroutinePool(tests.TestCase): self.assertEquals(['cons1', 'prod', 'cons2'], results) def test_timer_cancel(self): + timer_fired = [] + def fire_timer(): + timer_fired.append(True) def some_work(): - t = timer.Timer(5, lambda: None) - t.autocancellable = True - t.schedule() - return t + api.get_hub().schedule_call_local(0, fire_timer) pool = pools.CoroutinePool(0, 2) worker = pool.execute(some_work) - t = worker.wait() + worker.wait() api.sleep(0) - self.assertEquals(t.cancelled, True) + self.assertEquals(timer_fired, []) def test_reentrant(self): pool = pools.CoroutinePool(0,1)