Merge
This commit is contained in:
@@ -150,8 +150,8 @@ def trampoline(fd, read=False, write=False, 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:
|
||||
|
@@ -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_001_trampoline_timeout(self):
|
||||
server = api.tcp_listener(('0.0.0.0', 0))
|
||||
bound_port = server.getsockname()[1]
|
||||
|
||||
@@ -136,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()
|
||||
|
||||
|
@@ -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]
|
||||
|
@@ -51,8 +51,6 @@ import event
|
||||
|
||||
|
||||
class Hub(hub.BaseHub):
|
||||
SYSTEM_EXCEPTIONS = (KeyboardInterrupt, SystemExit)
|
||||
|
||||
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()
|
||||
|
@@ -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):
|
||||
|
@@ -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))
|
||||
|
Reference in New Issue
Block a user