diff --git a/engine.py b/engine.py index 47adfcb..f236661 100644 --- a/engine.py +++ b/engine.py @@ -1,4 +1,5 @@ import stackless +import greenlet import random import logging import pickle @@ -85,7 +86,7 @@ class Oob(object): self.ev.rgtk.append(self.tok) self.tok.mpevDgoob[self.ev] = self.dgoob def __exit__(self, etype, eval, tb): - if etype != TaskletExit: + if etype != greenlet.GreenletExit: try: self.tok.mpevDgoob.pop(self.ev) self.ev.rgtk.remove(self.tok) @@ -529,7 +530,7 @@ class Token(Taggable): def runI(self): try: self.run() - #except TaskletExit: + #except greenlet.GreenletExit: # raise except Exception: print "token script crashed:" diff --git a/stackless.py b/stackless.py index 8697b4a..67f923a 100644 --- a/stackless.py +++ b/stackless.py @@ -14,13 +14,15 @@ class Scheduler(object): self.rgtasklet.append(tasklet) def kill(self, tasklet): - if not tasklet.g.dead: - tasklet.g.parent = greenlet.getcurrent() - tasklet.g.throw() try: self.rgtasklet.remove(tasklet) except: pass + if tasklet.g == greenlet.getcurrent(): + raise greenlet.GreenletExit() + elif not tasklet.g.dead: + tasklet.g.parent = greenlet.getcurrent() + tasklet.g.throw() def run(self): self.g = greenlet.getcurrent()