From 64ad004e5d74cc691577fd43ba742a8db4ad2bf6 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sat, 13 Feb 2010 18:58:35 -0800 Subject: [PATCH] Moved timer to hubs package, since that's almost all of its usage. --- eventlet/debug.py | 2 +- eventlet/greenthread.py | 13 ++++++------- eventlet/hubs/hub.py | 6 +++--- eventlet/{ => hubs}/timer.py | 0 tests/timer_test.py | 6 ++++-- 5 files changed, 14 insertions(+), 13 deletions(-) rename eventlet/{ => hubs}/timer.py (100%) diff --git a/eventlet/debug.py b/eventlet/debug.py index a850232..937e6af 100644 --- a/eventlet/debug.py +++ b/eventlet/debug.py @@ -105,7 +105,7 @@ def hub_timer_stacks(state): To inspect the stacks of the current timers, call :func:`format_hub_timers` at critical junctures in the application logic. """ - from eventlet import timer + from eventlet.hubs import timer timer._g_debug = state def hub_exceptions(state): diff --git a/eventlet/greenthread.py b/eventlet/greenthread.py index 4b81d8a..bfaa555 100644 --- a/eventlet/greenthread.py +++ b/eventlet/greenthread.py @@ -2,7 +2,7 @@ import sys from eventlet import event from eventlet import hubs -from eventlet import timer +from eventlet.hubs import timer from eventlet.support import greenlets as greenlet __all__ = ['getcurrent', 'sleep', 'spawn', 'spawn_n', 'call_after_global', 'call_after_local', 'GreenThread'] @@ -292,19 +292,18 @@ def kill(g, *throw_args): # on its own; semantically we want it to be as though the main # method never got called def just_raise(*a, **kw): - raise throw_args or greenlet.GreenletExit + if throw_args: + raise throw_args[0], throw_args[1], throw_args[2] + else: + raise greenlet.GreenletExit() + g.run = just_raise if isinstance(g, GreenThread): # it's a GreenThread object, so we want to call its main # method to take advantage of the notification - g.run = just_raise try: g.main(just_raise, (), {}) except: pass - else: - # regular greenlet; just want to replace its run method so - # that whatever it was going to run, doesn't - g.run = just_raise hub.schedule_call_global(0, g.throw, *throw_args) if getcurrent() is not hub.greenlet: sleep(0) diff --git a/eventlet/hubs/hub.py b/eventlet/hubs/hub.py index 1486505..a86d0a9 100644 --- a/eventlet/hubs/hub.py +++ b/eventlet/hubs/hub.py @@ -4,7 +4,7 @@ import traceback import time from eventlet.support import greenlets as greenlet -from eventlet.timer import Timer, LocalTimer +from eventlet.hubs import timer READ="read" WRITE="write" @@ -208,7 +208,7 @@ class BaseHub(object): *args: Arguments to pass to the callable when called. **kw: Keyword arguments to pass to the callable when called. """ - t = LocalTimer(seconds, cb, *args, **kw) + t = timer.LocalTimer(seconds, cb, *args, **kw) self.add_timer(t) return t @@ -221,7 +221,7 @@ class BaseHub(object): *args: Arguments to pass to the callable when called. **kw: Keyword arguments to pass to the callable when called. """ - t = Timer(seconds, cb, *args, **kw) + t = timer.Timer(seconds, cb, *args, **kw) self.add_timer(t) return t diff --git a/eventlet/timer.py b/eventlet/hubs/timer.py similarity index 100% rename from eventlet/timer.py rename to eventlet/hubs/timer.py diff --git a/tests/timer_test.py b/tests/timer_test.py index 58e8230..a59767f 100644 --- a/tests/timer_test.py +++ b/tests/timer_test.py @@ -1,6 +1,8 @@ from unittest import TestCase, main -from eventlet import api, timer, hubs +import eventlet +from eventlet import hubs +from eventlet.hubs import timer class TestTimer(TestCase): def test_copy(self): @@ -16,7 +18,7 @@ class TestTimer(TestCase): # on this thread if hub.running: hub.abort() - api.sleep(0) + eventlet.sleep(0) called = [] #t = timer.Timer(0, lambda: (called.append(True), hub.abort())) #t.schedule()