From f6c483566b9309872ce4a83f8b19f62efeb8f5a4 Mon Sep 17 00:00:00 2001 From: rdw Date: Wed, 19 Mar 2008 09:49:28 -0500 Subject: [PATCH 1/4] Fixed api_test failure, tweaked some things, and made tpool_test faster and look more alive. --- eventlet/hubs/hub.py | 5 ++++- eventlet/hubs/libevent.py | 21 +++++++++++---------- eventlet/tests.py | 2 +- eventlet/tpool_test.py | 5 ++++- 4 files changed, 20 insertions(+), 13 deletions(-) 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)) From 4a2459b6bb1bfaaa3779d17bcbf7fb0c8297a8c3 Mon Sep 17 00:00:00 2001 From: rdw Date: Wed, 19 Mar 2008 15:57:50 -0500 Subject: [PATCH 2/4] Fixed test_trampoline_timeout. --- eventlet/api.py | 4 ++-- eventlet/api_test.py | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/eventlet/api.py b/eventlet/api.py index ffe6de2..4624541 100644 --- a/eventlet/api.py +++ b/eventlet/api.py @@ -136,8 +136,8 @@ def trampoline(fd, read=None, write=None, 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..9e0335f 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_trampoline_timeout(self): server = api.tcp_listener(('0.0.0.0', 0)) bound_port = server.getsockname()[1] From 2de6627f5a1dd0402fb51c52dc6fcd78c199792e Mon Sep 17 00:00:00 2001 From: rdw Date: Wed, 19 Mar 2008 16:06:52 -0500 Subject: [PATCH 3/4] test_explicit_hub seems to work --- eventlet/api_test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/eventlet/api_test.py b/eventlet/api_test.py index 9e0335f..a7e390b 100644 --- a/eventlet/api_test.py +++ b/eventlet/api_test.py @@ -133,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() From 9333192c32f73dfcb25c72598a76f12b213265b8 Mon Sep 17 00:00:00 2001 From: rdw Date: Wed, 19 Mar 2008 16:07:38 -0500 Subject: [PATCH 4/4] test_explicit_hub seems to work --- eventlet/api_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eventlet/api_test.py b/eventlet/api_test.py index a7e390b..53c5501 100644 --- a/eventlet/api_test.py +++ b/eventlet/api_test.py @@ -93,7 +93,7 @@ class TestApi(tests.TestCase): check_hub() - def test_trampoline_timeout(self): + def test_001_trampoline_timeout(self): server = api.tcp_listener(('0.0.0.0', 0)) bound_port = server.getsockname()[1]