Fixed timer canceling in CoroutinePool test, this mean that each coroutine in the pool is created anew.

This commit is contained in:
Ryan Williams
2009-06-02 17:50:24 -07:00
parent 821e88debd
commit d396d97414
2 changed files with 9 additions and 14 deletions

View File

@@ -274,7 +274,9 @@ class CoroutinePool(Pool):
def _main_loop(self, sender): def _main_loop(self, sender):
""" Private, infinite loop run by a pooled coroutine. """ """ Private, infinite loop run by a pooled coroutine. """
try: 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() recvd = sender.wait()
# Delete the sender's result here because the very # Delete the sender's result here because the very
# first event through the loop is referenced by # first event through the loop is referenced by
@@ -285,21 +287,14 @@ class CoroutinePool(Pool):
# tests. # tests.
sender._result = coros.NOT_USED sender._result = coros.NOT_USED
sender = coros.event()
(evt, func, args, kw) = recvd (evt, func, args, kw) = recvd
self._safe_apply(evt, func, args, kw) self._safe_apply(evt, func, args, kw)
#api.get_hub().cancel_timers(api.getcurrent())
# Likewise, delete these variables or else they will # Likewise, delete these variables or else they will
# be referenced by this frame until replaced by the # be referenced by this frame until replaced by the
# next recvd, which may or may not be a long time from # next recvd, which may or may not be a long time from
# now. # now.
del evt, func, args, kw, recvd del evt, func, args, kw, recvd
self.put(sender)
finally: 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()) self.put(self.create())
def _safe_apply(self, evt, func, args, kw): def _safe_apply(self, evt, func, args, kw):

View File

@@ -284,16 +284,16 @@ class TestCoroutinePool(tests.TestCase):
self.assertEquals(['cons1', 'prod', 'cons2'], results) self.assertEquals(['cons1', 'prod', 'cons2'], results)
def test_timer_cancel(self): def test_timer_cancel(self):
timer_fired = []
def fire_timer():
timer_fired.append(True)
def some_work(): def some_work():
t = timer.Timer(5, lambda: None) api.get_hub().schedule_call_local(0, fire_timer)
t.autocancellable = True
t.schedule()
return t
pool = pools.CoroutinePool(0, 2) pool = pools.CoroutinePool(0, 2)
worker = pool.execute(some_work) worker = pool.execute(some_work)
t = worker.wait() worker.wait()
api.sleep(0) api.sleep(0)
self.assertEquals(t.cancelled, True) self.assertEquals(timer_fired, [])
def test_reentrant(self): def test_reentrant(self):
pool = pools.CoroutinePool(0,1) pool = pools.CoroutinePool(0,1)