[pypy-svn] r28793 - in pypy/dist/pypy/module/_stackless: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Jun 15 00:24:55 CEST 2006


Author: cfbolz
Date: Thu Jun 15 00:24:52 2006
New Revision: 28793

Modified:
   pypy/dist/pypy/module/_stackless/coroutine.py
   pypy/dist/pypy/module/_stackless/interp_greenlet.py
   pypy/dist/pypy/module/_stackless/test/test_greenlet.py
Log:
cosmetics


Modified: pypy/dist/pypy/module/_stackless/coroutine.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/coroutine.py	(original)
+++ pypy/dist/pypy/module/_stackless/coroutine.py	Thu Jun 15 00:24:52 2006
@@ -89,7 +89,8 @@
         w_ret, state.w_tempval = state.w_tempval, space.w_None
         return w_ret
 
-    def w_finished(self): pass
+    def w_finished(self):
+        pass
 
     def finished(self):
         space = self.space

Modified: pypy/dist/pypy/module/_stackless/interp_greenlet.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/interp_greenlet.py	(original)
+++ pypy/dist/pypy/module/_stackless/interp_greenlet.py	Thu Jun 15 00:24:52 2006
@@ -45,9 +45,6 @@
     def post_install(self):
         self.current = self.main = AppGreenlet(self.space, is_main=True)
 
-class GreenletExit(Exception):
-    pass
-
 class AppGreenlet(Coroutine):
     def __init__(self, space, w_callable=None, is_main=False):
         self.space = space
@@ -179,8 +176,6 @@
     throw = interp2app(AppGreenlet.w_throw),
     gr_frame = GetSetProperty(w_get_frame),
     __nonzero__ = interp2app(descr__bool__),
-#    GreenletExit = GreenletExit,
-#    error = GreenletExit,
     __module__ = '_stackless',
 )
 

Modified: pypy/dist/pypy/module/_stackless/test/test_greenlet.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/test/test_greenlet.py	(original)
+++ pypy/dist/pypy/module/_stackless/test/test_greenlet.py	Thu Jun 15 00:24:52 2006
@@ -143,3 +143,52 @@
         assert next == "meaning of life"
         assert g.gr_frame is None
 
+    def test_mixing_greenlet_coroutine(self):
+        from _stackless import greenlet, coroutine
+        lst = []
+        def f():
+            lst.append(1)
+            greenlet.getcurrent().parent.switch()
+            lst.append(3)
+        def make_h(c):
+            def h():
+                g = greenlet(f)
+                lst.append(0)
+                g.switch()
+                c.switch()
+                lst.append(2)
+                g.switch()
+                c.switch()
+                lst.append(4)
+                c.switch()
+            return h
+        c1 = coroutine.getcurrent()
+        c2 = coroutine()
+        c3 = coroutine()
+        c2.bind(make_h(c3))
+        c3.bind(make_h(c2))
+        c2.switch()
+        assert lst == [0, 1, 0, 1, 2, 3, 2, 3, 4, 4]
+
+    def test_dealloc(self):
+        from _stackless import greenlet
+        import sys
+        def fmain(seen):
+            try:
+                greenlet.getcurrent().parent.switch()
+            except:
+                seen.append(sys.exc_info()[0])
+                raise
+            raise ValueError
+        seen = []
+        seen = []
+        g1 = greenlet(fmain)
+        g2 = greenlet(fmain)
+        g1.switch(seen)
+        g2.switch(seen)
+        assert seen == []
+        del g1
+        assert seen == [greenlet.GreenletExit]
+        del g2
+        assert seen == [greenlet.GreenletExit, greenlet.GreenletExit]
+



More information about the Pypy-commit mailing list