Moved timer to hubs package, since that's almost all of its usage.
This commit is contained in:
@@ -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):
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user