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

stephan at codespeak.net stephan at codespeak.net
Mon Jun 19 17:37:50 CEST 2006


Author: stephan
Date: Mon Jun 19 17:37:47 2006
New Revision: 28954

Modified:
   pypy/dist/pypy/lib/stackless.py
   pypy/dist/pypy/module/_stackless/test/test_coroutine.py
   pypy/dist/pypy/module/_stackless/test/test_stackless.py
Log:
started an attempt to do a tasklet cleanup. For some strange reason, coroutine.kill(c) seem to work with a pypy-c, but not with py.py (go figure).
If 'coro' is a coroutine, coro.is_zombie is not behaving as I would expect it.
So, either, I expect the wrong thing or coro.is_zombie is not doing the right thing. :-)


Modified: pypy/dist/pypy/lib/stackless.py
==============================================================================
--- pypy/dist/pypy/lib/stackless.py	(original)
+++ pypy/dist/pypy/lib/stackless.py	Mon Jun 19 17:37:47 2006
@@ -6,6 +6,12 @@
 
 import traceback
 import sys
+try:
+    deadtask = set()
+except NameError:
+    from sets import Set as set
+    deadtask = set()
+
 
 switches = 0
 
@@ -401,6 +407,7 @@
             else:
                 next = getmain()
             scheduler.remove_task(self)
+            deadtask.add(self)
             prev = self
             if excinfo[0] is not None:
                 et = excinfo[0]
@@ -727,14 +734,15 @@
         thisbomb = task.tempval
         assert isinstance(thisbomb, bomb)
         SETVAL(task, None)
-        try:
-            thisbomb._explode()
-        finally:
-            if getcurrent() == main_tasklet:
-                sys.excepthook(thisbomb.type, 
-                               thisbomb.value, 
-                               thisbomb.traceback)
-                sys.exit()
+        thisbomb._explode()
+#        try:
+#            thisbomb._explode()
+#        finally:
+#            if getcurrent() == main_tasklet:
+#                sys.excepthook(thisbomb.type, 
+#                               thisbomb.value, 
+#                               thisbomb.traceback)
+#                sys.exit()
         
     def _notify_schedule(self, prev, next, errflag):
         if _schedule_fasthook is not None:
@@ -781,6 +789,15 @@
         except:
             pass
 
+        for dead in tuple(deadtask):
+            deadtask.discard(dead)
+
+            # the code below should work, but doesn't
+
+            #if not dead.is_zombie:
+            #    coroutine.kill(dead)
+            #    del dead
+
         retval = prev.tempval
         if isinstance(retval, bomb):
             self.bomb_explode(prev)

Modified: pypy/dist/pypy/module/_stackless/test/test_coroutine.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_coroutine.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_coroutine.py	Mon Jun 19 17:37:47 2006
@@ -1,4 +1,5 @@
 from pypy.conftest import gettestobjspace, skip_on_missing_buildoption
+from py.test import skip
 
 # no real testing possible without compiling stackless pypy
 #
@@ -63,3 +64,34 @@
             pass
         else:
             raise AssertionError("exception not propagated")
+
+    def test_finished(self):
+        skip('should a coroutine be a zombie after being done?')
+        import _stackless as stackless
+        co = stackless.coroutine()
+        def f():
+            pass
+        co.bind(f)
+        co.switch()
+        # doing an assert here runs into some (infinite looking)
+        # cycle.
+        # Lots of "GC Warning: Finalization cycle involving xxxx"
+        if not co.is_zombie:
+            raise Exception('co should be a zombie now')
+
+    def test_kill(self):
+        skip('should a coroutine be a zombie after killing?')
+        # running this test actually produces an
+        # Fatal PyPy error: CoroutineExit (pypy-c)
+        # or
+        # some interpreter error when running on py.py
+        # actually, this looks quite similar to what I (stephan)
+        # have seen when playing around with the 'finish' routine
+        import _stackless as stackless
+        co = stackless.coroutine()
+        def f():
+            pass
+        co.bind(f)
+        co.kill()
+        if not co.is_zombie:
+            raise Exception('co should be a zombie now')

Modified: pypy/dist/pypy/module/_stackless/test/test_stackless.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_stackless.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_stackless.py	Mon Jun 19 17:37:47 2006
@@ -161,8 +161,7 @@
 
         assert rlist == "bg f E bh ag ah".split()
 
-    def test_except(self):
-        skip('not working yet')
+    def test_except_full(self):
         import stackless
         
         rlist = []
@@ -193,3 +192,12 @@
 
         assert rlist == "bg f E bh ag ah".split()
 
+    def test_kill(self):
+        skip('kill is not really working')
+        import stackless
+        def f():pass
+        t =  stackless.tasklet(f)()
+        t.kill()
+        assert not t.alive
+
+



More information about the Pypy-commit mailing list