Moved kill into greenthread, out of api.

This commit is contained in:
Ryan Williams
2010-01-17 17:11:55 -08:00
parent ed00c71d65
commit 977c985f75
3 changed files with 10 additions and 6 deletions

View File

@@ -10,7 +10,6 @@ sleep = greenthread.sleep
spawn = greenthread.spawn
spawn_n = greenthread.spawn_n
call_after_global = greenthread.call_after_global
call_after_local = greenthread.call_after_local
TimeoutError = greenthread.TimeoutError
exc_after = greenthread.exc_after
with_timeout = greenthread.with_timeout

View File

@@ -121,11 +121,7 @@ spawn = greenthread.spawn
spawn_n = greenthread.spawn_n
def kill(g, *throw_args):
get_hub_().schedule_call_global(0, g.throw, *throw_args)
if getcurrent() is not get_hub_().greenlet:
sleep(0)
kill = greenthread.kill
call_after = greenthread.call_after
call_after_local = greenthread.call_after_local

View File

@@ -8,6 +8,15 @@ __all__ = ['getcurrent', 'sleep', 'spawn', 'spawn_n', 'call_after_global', 'call
getcurrent = greenlet.getcurrent
def kill(g, *throw_args):
"""Terminates the target greenthread by raising an exception into it.
By default, this exception is GreenletExit, but a specific exception
may be specified in the *throw_args*.
"""
get_hub_().schedule_call_global(0, g.throw, *throw_args)
if getcurrent() is not get_hub_().greenlet:
sleep(0)
def sleep(seconds=0):
"""Yield control to another eligible coroutine until at least *seconds* have
elapsed.