proc fix: Source.wait(0) used to do the wrong thing - return None instead of raising TimeoutError

This commit is contained in:
Denis Bilenko
2009-01-21 13:21:02 +06:00
parent dad443c230
commit 69cf736155
2 changed files with 27 additions and 8 deletions

View File

@@ -387,11 +387,19 @@ class Source(object):
return self._result return self._result
else: else:
api.getcurrent().throw(*self._exc) api.getcurrent().throw(*self._exc)
if timeout==0:
return
if timeout is not None: if timeout is not None:
timer = api.timeout(timeout, *throw_args) timer = api.timeout(timeout, *throw_args)
timer.__enter__() timer.__enter__()
if timeout==0:
if timer.__exit__(None, None, None):
return
else:
try:
api.getcurrent().throw(*timer.throw_args)
except:
if not timer.__exit__(*sys.exc_info()):
raise
return
EXC = True EXC = True
try: try:
try: try:

View File

@@ -27,14 +27,17 @@ from greentest import LimitedTestCase
DELAY = 0.01 DELAY = 0.01
class TestEventSource(LimitedTestCase):
class TestLink_Signal(LimitedTestCase):
def test_send(self): def test_send(self):
s = proc.Source() s = proc.Source()
q1, q2, q3 = coros.queue(), coros.queue(), coros.queue() q1, q2, q3 = coros.queue(), coros.queue(), coros.queue()
s.link_value(q1) s.link_value(q1)
assert s.wait(0) is None self.assertRaises(api.TimeoutError, s.wait, 0)
assert s.wait(0, None) is None
assert s.wait(0.001, None) is None assert s.wait(0.001, None) is None
self.assertRaises(api.TimeoutError, s.wait, 0.001)
s.send(1) s.send(1)
assert not q1.ready() assert not q1.ready()
assert s.wait()==1 assert s.wait()==1
@@ -64,7 +67,7 @@ class TestEventSource(LimitedTestCase):
self.assertRaises(OSError, s.wait) self.assertRaises(OSError, s.wait)
class SimpleTestProc(LimitedTestCase): class TestProc(LimitedTestCase):
def test_proc(self): def test_proc(self):
p = proc.spawn(lambda : 100) p = proc.spawn(lambda : 100)
@@ -342,10 +345,9 @@ class TestStuff(unittest.TestCase):
sleep(DELAY*10) sleep(DELAY*10)
assert results in [[10, 20], [20, 10]], results assert results in [[10, 20], [20, 10]], results
def test_multiple_listeners_error_unlink(self): def _test_multiple_listeners_error_unlink(self, p):
# notification must not happen after unlink even # notification must not happen after unlink even
# though notification process has been already started # though notification process has been already started
p = proc.spawn(lambda : 5)
results = [] results = []
def listener1(*args): def listener1(*args):
p.unlink(listener2) p.unlink(listener2)
@@ -363,6 +365,15 @@ class TestStuff(unittest.TestCase):
sleep(DELAY*10) sleep(DELAY*10)
assert results == [5], results assert results == [5], results
def test_multiple_listeners_error_unlink_Proc(self):
p = proc.spawn(lambda : 5)
self._test_multiple_listeners_error_unlink(p)
def test_multiple_listeners_error_unlink_Source(self):
p = proc.Source()
proc.spawn(p.send, 6)
self._test_multiple_listeners_error_unlink(p)
def test_killing_unlinked(self): def test_killing_unlinked(self):
e = coros.event() e = coros.event()
def func(): def func():
@@ -377,7 +388,7 @@ class TestStuff(unittest.TestCase):
except ZeroDivisionError: except ZeroDivisionError:
pass pass
finally: finally:
p.unlink() p.unlink() # this disables LinkedCompleted that otherwise would be raised by the next line
sleep(DELAY) sleep(DELAY)