Skip to content

Commit

Permalink
Merge pull request #608 from sublee/fix-607
Browse files Browse the repository at this point in the history
Fix 607
  • Loading branch information
jamadden committed Jul 10, 2015
2 parents cd634cd + 114753f commit 1d80700
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gevent/greenlet.py
Expand Up @@ -357,7 +357,7 @@ def kill(self, exception=GreenletExit, block=True, timeout=None):
self.__cancel_start()

if self.dead:
self.__handle_death_before_start()
self.__handle_death_before_start(exception)
else:
waiter = Waiter()
self.parent.loop.run_callback(_kill, self, exception, waiter)
Expand Down
42 changes: 42 additions & 0 deletions greentest/test__issue607.py
@@ -0,0 +1,42 @@
# A greenlet that's killed with an exception should fail.
import greentest
import gevent


class ExpectedError(greentest.ExpectedException):
pass


def f():
gevent.sleep(999)


class TestKillWithException(greentest.TestCase):

def test_kill_without_exception(self):
g = gevent.spawn(f)
g.kill()
assert g.successful()
assert isinstance(g.get(), gevent.GreenletExit)

def test_kill_with_exception(self):
# issue-607 pointed this case.
g = gevent.spawn(f)
g.kill(ExpectedError)
assert not g.successful()
self.assertRaises(ExpectedError, g.get)
assert g.value is None
assert isinstance(g.exception, ExpectedError)

def test_kill_with_exception_after_started(self):
g = gevent.spawn(f)
g.join(0)
g.kill(ExpectedError)
assert not g.successful()
self.assertRaises(ExpectedError, g.get)
assert g.value is None
assert isinstance(g.exception, ExpectedError)


if __name__ == '__main__':
greentest.main()

0 comments on commit 1d80700

Please sign in to comment.