Commit 55934de4 authored by Denis Bilenko's avatar Denis Bilenko

hub: immediatelly raise system error

previously it was added to the queue of callbacks.
Update test__systemerror.py
parent 6da9a8b5
...@@ -318,7 +318,13 @@ class Hub(greenlet): ...@@ -318,7 +318,13 @@ class Hub(greenlet):
if current is self or current is self.parent or self.loop is None: if current is self or current is self.parent or self.loop is None:
self.parent.throw(type, value) self.parent.throw(type, value)
else: else:
self.loop.run_callback(self.parent.throw, type, value) # in case system error was handled and life goes on
# switch back to this greenlet as well
cb = self.loop.run_callback(current.switch)
try:
self.parent.throw(type, value)
finally:
cb.stop()
def print_exception(self, context, type, value, tb): def print_exception(self, context, type, value, tb):
traceback.print_exception(type, value, tb) traceback.print_exception(type, value, tb)
......
...@@ -23,6 +23,8 @@ class Test(greentest.TestCase): ...@@ -23,6 +23,8 @@ class Test(greentest.TestCase):
except SystemExit: except SystemExit:
ex = sys.exc_info()[1] ex = sys.exc_info()[1]
assert str(ex) == MSG, repr(str(ex)) assert str(ex) == MSG, repr(str(ex))
else:
raise AssertionError('must raise SystemExit')
def test_keyboard_interrupt(self): def test_keyboard_interrupt(self):
self.start(raise_, KeyboardInterrupt) self.start(raise_, KeyboardInterrupt)
...@@ -31,6 +33,8 @@ class Test(greentest.TestCase): ...@@ -31,6 +33,8 @@ class Test(greentest.TestCase):
gevent.sleep(0.001) gevent.sleep(0.001)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
else:
raise AssertionError('must raise KeyboardInterrupt')
def test_system_error(self): def test_system_error(self):
self.start(raise_, SystemError(MSG)) self.start(raise_, SystemError(MSG))
...@@ -40,6 +44,8 @@ class Test(greentest.TestCase): ...@@ -40,6 +44,8 @@ class Test(greentest.TestCase):
except SystemError: except SystemError:
ex = sys.exc_info()[1] ex = sys.exc_info()[1]
assert str(ex) == MSG, repr(str(ex)) assert str(ex) == MSG, repr(str(ex))
else:
raise AssertionError('must raise SystemError')
def test_exception(self): def test_exception(self):
self.start(raise_, Exception('regular exception must not kill the program')) self.start(raise_, Exception('regular exception must not kill the program'))
...@@ -58,6 +64,7 @@ class TestCallback(Test): ...@@ -58,6 +64,7 @@ class TestCallback(Test):
class TestSpawn(Test): class TestSpawn(Test):
def tearDown(self): def tearDown(self):
gevent.sleep(0.0001)
assert self.x.dead, self.x assert self.x.dead, self.x
def start(self, *args): def start(self, *args):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment