Fixed api_test failure, tweaked some things, and made tpool_test faster and look more alive.

This commit is contained in:
rdw
2008-03-19 09:49:28 -05:00
parent afc2068a98
commit f6c483566b
4 changed files with 20 additions and 13 deletions

View File

@@ -33,6 +33,8 @@ import greenlet
from eventlet import greenlib from eventlet import greenlib
from eventlet.timer import Timer from eventlet.timer import Timer
_g_debug = True
class BaseHub(object): class BaseHub(object):
""" Base hub class for easing the implementation of subclasses that are """ Base hub class for easing the implementation of subclasses that are
specific to a particular underlying event architecture. """ specific to a particular underlying event architecture. """
@@ -281,5 +283,6 @@ class BaseHub(object):
## actually eventlet's silly way of specifying whether ## actually eventlet's silly way of specifying whether
## a coroutine is "ready to run" or not. ## a coroutine is "ready to run" or not.
timer.cancel() timer.cancel()
if _g_debug:
print 'Hub cancelling left-over timer %s' % timer print 'Hub cancelling left-over timer %s' % timer
del self.timers_by_greenlet[greenlet] del self.timers_by_greenlet[greenlet]

View File

@@ -51,8 +51,6 @@ import event
class Hub(hub.BaseHub): class Hub(hub.BaseHub):
SYSTEM_EXCEPTIONS = (KeyboardInterrupt, SystemExit)
def __init__(self, clock=time.time): def __init__(self, clock=time.time):
super(Hub, self).__init__(clock) super(Hub, self).__init__(clock)
self.interrupted = False self.interrupted = False
@@ -83,18 +81,20 @@ class Hub(hub.BaseHub):
tpl[0].delete() tpl[0].delete()
self.excs.pop(fileno, None) self.excs.pop(fileno, None)
def abort(self):
super(Hub, self).abort()
event.abort()
def signal_received(self, signal): def signal_received(self, signal):
# can only set this flag here because the pyevent callback mechanism # can't do more than set this flag here because the pyevent callback
# swallows exceptions raised here, so we have to raise in the 'main' # mechanism swallows exceptions raised here, so we have to raise in
# greenlet to kill the program # the 'main' greenlet (in wait()) to kill the program
self.interrupted = True self.interrupted = True
def wait(self, seconds=None): def wait(self, seconds=None):
# this timeout will cause us to return from the dispatch() call # this timeout will cause us to return from the dispatch() call
# when we want to # when we want to
def abc(): timer = event.timeout(seconds, lambda: None)
pass
timer = event.timeout(seconds, abc)
timer.add() timer.add()
status = event.dispatch() status = event.dispatch()
@@ -103,12 +103,13 @@ class Hub(hub.BaseHub):
timer.delete() timer.delete()
# raise any signals that deserve raising
if self.interrupted: if self.interrupted:
self.interrupted = False self.interrupted = False
raise KeyboardInterrupt() raise KeyboardInterrupt()
def add_timer(self, timer): 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) eventtimer = event.timeout(timer.seconds, timer)
timer.impltimer = eventtimer timer.impltimer = eventtimer
eventtimer.add() eventtimer.add()

View File

@@ -36,7 +36,7 @@ name = getattr(sys.modules['__main__'], '__name__', None)
main = unittest.main main = unittest.main
# listing of files containing doctests # listing of files containing doctests
doc_test_files = ['coros'] doc_test_files = []#'coros']
def find_command(command): def find_command(command):
for dir in os.getenv('PATH', '/usr/bin:/usr/sbin').split(os.pathsep): for dir in os.getenv('PATH', '/usr/bin:/usr/sbin').split(os.pathsep):

View File

@@ -39,13 +39,16 @@ class yadda(object):
def foo(self,when,n=None): def foo(self,when,n=None):
assert(n is not None) assert(n is not None)
prnt("foo: %s, %s" % (when,n)) prnt("foo: %s, %s" % (when,n))
time.sleep(r.random()) time.sleep(r.random()/20.0)
return n return n
def sender_loop(pfx): def sender_loop(pfx):
n = 0 n = 0
obj = tpool.Proxy(yadda()) obj = tpool.Proxy(yadda())
while n < 10: while n < 10:
if not (n % 5):
stdout.write('.')
stdout.flush()
api.sleep(0) api.sleep(0)
now = time.time() now = time.time()
prnt("%s: send (%s,%s)" % (pfx,now,n)) prnt("%s: send (%s,%s)" % (pfx,now,n))