Commit 81f2552e authored by Jason Madden's avatar Jason Madden

Raise the correct exception from gevent.kill. Fixes #623.

parent e2ec8bb7
......@@ -11,6 +11,8 @@ Unreleased
- On some versions of PyPy on some platforms (notably 2.6.0 on 64-bit
Linux), enabling ``gevent.monkey.patch_builtins`` could cause PyPy
to crash. Reported in :issue:`618` by Jay Oster.
- ``gevent.kill`` raises the correct exception in the target greenlet.
Reported in :issue:`623` by Jonathan Kamens.
1.1b1 (Jul 17, 2015)
====================
......
......@@ -127,7 +127,7 @@ class FileObjectPosix(object):
"""
A file-like object that operates on non-blocking files.
.. sealso:: :func:`gevent.os.make_nonblocking`
.. seelso:: :func:`gevent.os.make_nonblocking`
"""
default_bufsize = io.DEFAULT_BUFFER_SIZE
......
......@@ -399,7 +399,7 @@ class Greenlet(greenlet):
if self.dead:
self.__handle_death_before_start(exception)
else:
waiter = Waiter()
waiter = Waiter() if block else None
self.parent.loop.run_callback(_kill, self, exception, waiter)
if block:
waiter.get()
......@@ -578,7 +578,8 @@ def _kill(greenlet, exception, waiter):
except:
# XXX do we need this here?
greenlet.parent.handle_error(greenlet, *sys.exc_info())
waiter.switch()
if waiter is not None:
waiter.switch()
def joinall(greenlets, timeout=None, raise_error=False, count=None):
......
......@@ -157,7 +157,7 @@ def kill(greenlet, exception=GreenletExit):
# dealing with gevent.greenlet.Greenlet. Use it, especially
# to avoid allowing one to be switched to for the first time
# after it's been killed
greenlet.kill(block=False)
greenlet.kill(exception=exception, block=False)
else:
get_hub().loop.run_callback(greenlet.throw, exception)
......
# Copyright (c) 2009-2014 Denis Bilenko and gevent contributors. See LICENSE for details.
"""Cooperative socket module.
"""Cooperative low-level networking interface.
This module provides socket operations and some related functions.
The API of the functions and classes matches the API of the corresponding
......
......@@ -44,3 +44,24 @@ g2 = gevent.spawn(runner, 1)
g.throw(gevent.GreenletExit)
g2.throw(gevent.GreenletExit)
check(g, g2)
# Killing with gevent.kill gets the right exception
class MyException(Exception):
pass
def catcher():
try:
while True:
gevent.sleep(0)
except Exception as e:
switched_to[0] = e
g = gevent.spawn(catcher)
g.start()
gevent.sleep()
gevent.kill(g, MyException())
gevent.sleep()
assert isinstance(switched_to[0], MyException), switched_to
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