Moved timer to hubs package, since that's almost all of its usage.

This commit is contained in:
Ryan Williams
2010-02-13 18:58:35 -08:00
parent 695159bdb1
commit 64ad004e5d
5 changed files with 14 additions and 13 deletions

View File

@@ -105,7 +105,7 @@ def hub_timer_stacks(state):
To inspect the stacks of the current timers, call :func:`format_hub_timers` To inspect the stacks of the current timers, call :func:`format_hub_timers`
at critical junctures in the application logic. at critical junctures in the application logic.
""" """
from eventlet import timer from eventlet.hubs import timer
timer._g_debug = state timer._g_debug = state
def hub_exceptions(state): def hub_exceptions(state):

View File

@@ -2,7 +2,7 @@ import sys
from eventlet import event from eventlet import event
from eventlet import hubs from eventlet import hubs
from eventlet import timer from eventlet.hubs import timer
from eventlet.support import greenlets as greenlet from eventlet.support import greenlets as greenlet
__all__ = ['getcurrent', 'sleep', 'spawn', 'spawn_n', 'call_after_global', 'call_after_local', 'GreenThread'] __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 # on its own; semantically we want it to be as though the main
# method never got called # method never got called
def just_raise(*a, **kw): 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): if isinstance(g, GreenThread):
# it's a GreenThread object, so we want to call its main # it's a GreenThread object, so we want to call its main
# method to take advantage of the notification # method to take advantage of the notification
g.run = just_raise
try: try:
g.main(just_raise, (), {}) g.main(just_raise, (), {})
except: except:
pass 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) hub.schedule_call_global(0, g.throw, *throw_args)
if getcurrent() is not hub.greenlet: if getcurrent() is not hub.greenlet:
sleep(0) sleep(0)

View File

@@ -4,7 +4,7 @@ import traceback
import time import time
from eventlet.support import greenlets as greenlet from eventlet.support import greenlets as greenlet
from eventlet.timer import Timer, LocalTimer from eventlet.hubs import timer
READ="read" READ="read"
WRITE="write" WRITE="write"
@@ -208,7 +208,7 @@ class BaseHub(object):
*args: Arguments to pass to the callable when called. *args: Arguments to pass to the callable when called.
**kw: Keyword 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) self.add_timer(t)
return t return t
@@ -221,7 +221,7 @@ class BaseHub(object):
*args: Arguments to pass to the callable when called. *args: Arguments to pass to the callable when called.
**kw: Keyword 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) self.add_timer(t)
return t return t

View File

@@ -1,6 +1,8 @@
from unittest import TestCase, main 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): class TestTimer(TestCase):
def test_copy(self): def test_copy(self):
@@ -16,7 +18,7 @@ class TestTimer(TestCase):
# on this thread # on this thread
if hub.running: if hub.running:
hub.abort() hub.abort()
api.sleep(0) eventlet.sleep(0)
called = [] called = []
#t = timer.Timer(0, lambda: (called.append(True), hub.abort())) #t = timer.Timer(0, lambda: (called.append(True), hub.abort()))
#t.schedule() #t.schedule()