[pypy-svn] r28765 - in pypy/dist/pypy: lib module/_stackless

stephan at codespeak.net stephan at codespeak.net
Wed Jun 14 12:30:13 CEST 2006


Author: stephan
Date: Wed Jun 14 12:30:11 2006
New Revision: 28765

Modified:
   pypy/dist/pypy/lib/stackless.py
   pypy/dist/pypy/module/_stackless/coroutine.py
   pypy/dist/pypy/module/_stackless/interp_coroutine.py
Log:
added a 'finished' method to Coroutine. It gets called just before 'self.thunk' is set to 'None' in Coroutine._execute.
AppCouroutine lifts this to AppLevel, so it can be used for signaling (this is used in stackless)


Modified: pypy/dist/pypy/lib/stackless.py
==============================================================================
--- pypy/dist/pypy/lib/stackless.py	(original)
+++ pypy/dist/pypy/lib/stackless.py	Wed Jun 14 12:30:11 2006
@@ -439,6 +439,10 @@
         if func is not None:
             self.bind(func)
 
+    def __del__(self):
+        if DEBUG:
+            print 'in __del__', self
+
     def __call__(self, *argl, **argd):
         self.setup(*argl, **argd)
         return self
@@ -571,6 +575,13 @@
     ## tasklet(func)(*args, **kwds)
     ## is identical to
     ## t = tasklet; t.bind(func); t.setup(*args, **kwds)
+
+    def finished(self):
+        self.alive = False
+        scheduler.remove_task(self)
+
+        print 'in finished', self
+
     def setup(self, *argl, **argd):
         """
         supply the parameters for the callable
@@ -957,10 +968,7 @@
             SETPREV(task, l)
             SETNEXT(task, r)
 
-    def _chain_remove(self):
-        if self._head is None: 
-            return None
-        task = self._head
+    def remove_task(self, task):
         l = task.prev
         r = task.next
         SETNEXT(l, r)
@@ -972,6 +980,10 @@
 
         return task
 
+    def _chain_remove(self):
+        if self._head is None: 
+            return None
+        return self.remove_task(self._head)
 
     def current_insert(self, task):
         self._chain_insert(task)

Modified: pypy/dist/pypy/module/_stackless/coroutine.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/coroutine.py	(original)
+++ pypy/dist/pypy/module/_stackless/coroutine.py	Wed Jun 14 12:30:11 2006
@@ -89,6 +89,12 @@
         w_ret, state.w_tempval = state.w_tempval, space.w_None
         return w_ret
 
+    def w_finished(self): pass
+
+    def finished(self):
+        space = self.space
+        return space.call_method(space.wrap(self),'finished')
+
     def hello(self):
         ec = self.space.getexecutioncontext()
         ec.subcontext_enter(self)
@@ -101,6 +107,7 @@
         self.kill()
 
     def _userdel(self):
+        print 'in userdel'
         if self.get_is_zombie():
             return
         self.set_is_zombie(True)
@@ -240,6 +247,7 @@
                       unwrap_spec=['self', W_Root, Arguments]),
     switch = interp2app(AppCoroutine.w_switch),
     kill = interp2app(AppCoroutine.w_kill),
+    finished = interp2app(AppCoroutine.w_finished),
     is_zombie = GetSetProperty(AppCoroutine.w_get_is_zombie, doc=AppCoroutine.get_is_zombie.__doc__),
     _framestack = GetSetProperty(w_descr__framestack),
     getcurrent = interp2app(AppCoroutine.w_getcurrent),

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	Wed Jun 14 12:30:11 2006
@@ -211,6 +211,7 @@
             try:
                 self.thunk.call()
             finally:
+                self.finished()
                 self.thunk = None
             resume_point("coroutine__bind", self, state)
         except CoroutineExit:
@@ -290,4 +291,7 @@
     def goodbye(self):
         "Called just after execution is transferred away from this coroutine."
 
+    def finished(self):
+        "Called just after frame died"
+
 # _________________________________________________



More information about the Pypy-commit mailing list