Commits

Armin Rigo committed 02f3dda

Test for the "except:" path. Tests that the exception class is only
instantiated once, and fix.

Comments (0)

Files changed (2)

lib_pypy/greenlet.py

+import sys
 import _continuation
 
 __version__ = "0.4.0"
                     methodname = 'switch'
                     baseargs = (((e,), {}),)
                 except:
-                    pass
-                convert_greenletexit = False
+                    baseargs = sys.exc_info()[:2] + baseargs[2:]
+                    convert_greenletexit = False
         #
         try:
             unbound_method = getattr(_continulet, methodname)

pypy/module/test_lib_pypy/test_greenlet.py

         e = greenlet.GreenletExit()
         x = g.throw(e)
         assert x is e
+
+    def test_throw_exception_already_finished(self):
+        import greenlet
+        def f():
+            pass
+        g = greenlet.greenlet(f)
+        g.switch()
+        seen = []
+        class MyException(Exception):
+            def __init__(self):
+                seen.append(1)
+        try:
+            g.throw(MyException)
+        except MyException:
+            pass
+        else:
+            raise AssertionError("no exception??")
+        assert seen == [1]