[pypy-svn] r28898 - pypy/dist/pypy/module/_stackless

stephan at codespeak.net stephan at codespeak.net
Fri Jun 16 21:05:17 CEST 2006


Author: stephan
Date: Fri Jun 16 21:05:07 2006
New Revision: 28898

Modified:
   pypy/dist/pypy/module/_stackless/coroutine.py
   pypy/dist/pypy/module/_stackless/interp_coroutine.py
Log:
I've changed exception handling in interp_coroutine.py in order to
get the right stackless behaviour. Basicly, if a coroutine finishes by
a raised exception, this exception (or rather, the error object) is given
to uplevel tasklet, to do something about it. The downside is that
tasklets are not cleaned away. So, this needs to be rewritten, but not
before the release.


Modified: pypy/dist/pypy/module/_stackless/coroutine.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/coroutine.py	(original)
+++ pypy/dist/pypy/module/_stackless/coroutine.py	Fri Jun 16 21:05:07 2006
@@ -89,12 +89,18 @@
         w_ret, state.w_tempval = state.w_tempval, space.w_None
         return w_ret
 
-    def w_finished(self):
+    def w_finished(self, w_exctype=None, w_excvalue=None):
         pass
 
-    def finished(self):
+    def finish(self, operror=None):
         space = self.space
-        return space.call_method(space.wrap(self),'finished')
+        w_exctype = space.w_None
+        w_excvalue = space.w_None
+        if operror is not None:
+            w_exctype = operror.w_type
+            w_excvalue = operror.w_value
+
+        return space.call_method(space.wrap(self),'finished', w_exctype, w_excvalue)
 
     def hello(self):
         ec = self.space.getexecutioncontext()

Modified: pypy/dist/pypy/module/_stackless/interp_coroutine.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/interp_coroutine.py	(original)
+++ pypy/dist/pypy/module/_stackless/interp_coroutine.py	Fri Jun 16 21:05:07 2006
@@ -213,10 +213,15 @@
         state = self.costate
         try:
             try:
-                self.thunk.call()
-                resume_point("coroutine__bind", self, state)
+                try:
+                    exc = None
+                    self.thunk.call()
+                    resume_point("coroutine__bind", self, state)
+                except Exception, e:
+                    exc = e
+                    raise
             finally:
-                self.finished()
+                self.finish(exc)
                 self.thunk = None
         except CoroutineExit:
             # ignore a shutdown exception
@@ -224,7 +229,7 @@
         except Exception, e:
             # redirect all unhandled exceptions to the parent
             syncstate.things_to_do = True
-            syncstate.temp_exc = e
+            syncstate.temp_exc = exc
         while self.parent is not None and self.parent.frame is None:
             # greenlet behavior is fine
             self.parent = self.parent.parent



More information about the Pypy-commit mailing list