diff options
author | Armin Rigo <arigo@tunes.org> | 2011-08-19 15:25:54 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2011-08-19 15:25:54 +0200 |
commit | f25d52c141648a4c98c0aa503cdc39215508e115 (patch) | |
tree | 0ac6da0b43ad294f7762978cbd130a58bbdd92c5 /lib_pypy/greenlet.py | |
parent | Test for the 'parent' attribute. (diff) | |
download | pypy-f25d52c141648a4c98c0aa503cdc39215508e115.tar.gz pypy-f25d52c141648a4c98c0aa503cdc39215508e115.tar.bz2 pypy-f25d52c141648a4c98c0aa503cdc39215508e115.zip |
throw().
Diffstat (limited to 'lib_pypy/greenlet.py')
-rw-r--r-- | lib_pypy/greenlet.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py index 0c15dd8dd8..816bc238da 100644 --- a/lib_pypy/greenlet.py +++ b/lib_pypy/greenlet.py @@ -41,12 +41,19 @@ class greenlet(_continulet): def switch(self, *args): "Switch execution to this greenlet, optionally passing the values " "given as argument(s). Returns the value passed when switching back." + return self.__switch(_continulet.switch, args) + + def throw(self, typ=GreenletExit, val=None, tb=None): + "raise exception in greenlet, return value passed when switching back" + return self.__switch(_continulet.throw, typ, val, tb) + + def __switch(self, unbound_method, *args): current = getcurrent() target = self if not target.is_pending() and not target.__main: if not target.__started: - _continulet.__init__(target, _greenlet_start, args) - args = None + _continulet.__init__(target, _greenlet_start, *args) + args = (None,) target.__started = True else: # already done, go to main instead... xxx later @@ -56,17 +63,18 @@ class greenlet(_continulet): if current.__main: if target.__main: # switch from main to main - pass + if unbound_method == _continulet.throw: + raise args[0], args[1], args[2] else: # enter from main to target - args = _continulet.switch(target, args) + args = unbound_method(target, *args) else: if target.__main: # leave to go to target=main - args = _continulet.switch(current, args) + args = unbound_method(current, *args) else: # switch from non-main to non-main - args = _continulet.switch(current, args, to=target) + args = unbound_method(current, *args, to=target) except GreenletExit, e: args = (e,) finally: @@ -77,10 +85,6 @@ class greenlet(_continulet): else: return args - def throw(self, typ=GreenletExit, val=None, tb=None): - "raise exception in greenlet, return value passed when switching back" - XXX - __nonzero__ = _continulet.is_pending @property |