diff --git a/eventlet/api.py b/eventlet/api.py index dbffb7e..b163ea1 100644 --- a/eventlet/api.py +++ b/eventlet/api.py @@ -150,8 +150,8 @@ def trampoline(fd, read=False, write=False, timeout=None): def _do_close(fn): hub.remove_descriptor(fn) greenlib.switch(self, exc=socket.error(32, 'Broken pipe')) - def _do_timeout(fn): - hub.remove_descriptor(fn) + def _do_timeout(): + hub.remove_descriptor(fileno) greenlib.switch(self, exc=TimeoutError()) def cb(_fileno): if t is not None: diff --git a/eventlet/api_test.py b/eventlet/api_test.py index 6557554..53c5501 100644 --- a/eventlet/api_test.py +++ b/eventlet/api_test.py @@ -93,10 +93,7 @@ class TestApi(tests.TestCase): check_hub() - def dont_test_trampoline_timeout(self): - """This test is broken. Please change it's name to test_trampoline_timeout, - and fix the bug (or fix the test) - """ + def test_001_trampoline_timeout(self): server = api.tcp_listener(('0.0.0.0', 0)) bound_port = server.getsockname()[1] @@ -136,10 +133,7 @@ class TestApi(tests.TestCase): check_hub() - def dont_test_explicit_hub(self): - """This test is broken. please change it's name to test_explicit_hub - and make it pass (or fix the test) - """ + def test_explicit_hub(self): api.use_hub(Foo) assert isinstance(api.get_hub(), Foo), api.get_hub() diff --git a/eventlet/hubs/hub.py b/eventlet/hubs/hub.py index a02104f..c86aefa 100644 --- a/eventlet/hubs/hub.py +++ b/eventlet/hubs/hub.py @@ -33,6 +33,8 @@ import greenlet from eventlet import greenlib from eventlet.timer import Timer +_g_debug = True + class BaseHub(object): """ Base hub class for easing the implementation of subclasses that are specific to a particular underlying event architecture. """ @@ -281,5 +283,6 @@ class BaseHub(object): ## actually eventlet's silly way of specifying whether ## a coroutine is "ready to run" or not. timer.cancel() - print 'Hub cancelling left-over timer %s' % timer + if _g_debug: + print 'Hub cancelling left-over timer %s' % timer del self.timers_by_greenlet[greenlet] diff --git a/eventlet/hubs/libevent.py b/eventlet/hubs/libevent.py index 7865e90..10327e1 100644 --- a/eventlet/hubs/libevent.py +++ b/eventlet/hubs/libevent.py @@ -50,9 +50,7 @@ except ImportError: import event -class Hub(hub.BaseHub): - SYSTEM_EXCEPTIONS = (KeyboardInterrupt, SystemExit) - +class Hub(hub.BaseHub): def __init__(self, clock=time.time): super(Hub, self).__init__(clock) self.interrupted = False @@ -83,18 +81,20 @@ class Hub(hub.BaseHub): tpl[0].delete() self.excs.pop(fileno, None) + def abort(self): + super(Hub, self).abort() + event.abort() + def signal_received(self, signal): - # can only set this flag here because the pyevent callback mechanism - # swallows exceptions raised here, so we have to raise in the 'main' - # greenlet to kill the program + # can't do more than set this flag here because the pyevent callback + # mechanism swallows exceptions raised here, so we have to raise in + # the 'main' greenlet (in wait()) to kill the program self.interrupted = True def wait(self, seconds=None): # this timeout will cause us to return from the dispatch() call # when we want to - def abc(): - pass - timer = event.timeout(seconds, abc) + timer = event.timeout(seconds, lambda: None) timer.add() status = event.dispatch() @@ -103,12 +103,13 @@ class Hub(hub.BaseHub): timer.delete() + # raise any signals that deserve raising if self.interrupted: self.interrupted = False raise KeyboardInterrupt() def add_timer(self, timer): - # eventtimer is the pyevent object representing the timer + # store the pyevent timer object so that we can cancel later eventtimer = event.timeout(timer.seconds, timer) timer.impltimer = eventtimer eventtimer.add() diff --git a/eventlet/tests.py b/eventlet/tests.py index 41968c2..7caab69 100644 --- a/eventlet/tests.py +++ b/eventlet/tests.py @@ -36,7 +36,7 @@ name = getattr(sys.modules['__main__'], '__name__', None) main = unittest.main # listing of files containing doctests -doc_test_files = ['coros'] +doc_test_files = []#'coros'] def find_command(command): for dir in os.getenv('PATH', '/usr/bin:/usr/sbin').split(os.pathsep): diff --git a/eventlet/tpool_test.py b/eventlet/tpool_test.py index 19442bc..fbc85d6 100644 --- a/eventlet/tpool_test.py +++ b/eventlet/tpool_test.py @@ -39,13 +39,16 @@ class yadda(object): def foo(self,when,n=None): assert(n is not None) prnt("foo: %s, %s" % (when,n)) - time.sleep(r.random()) + time.sleep(r.random()/20.0) return n def sender_loop(pfx): n = 0 obj = tpool.Proxy(yadda()) while n < 10: + if not (n % 5): + stdout.write('.') + stdout.flush() api.sleep(0) now = time.time() prnt("%s: send (%s,%s)" % (pfx,now,n))