Cython generators clear the current exception #1731

Open
jbradaric opened this Issue Jun 12, 2017 · 0 comments

Comments

Projects
None yet
1 participant

Cython version 0.25.2

To reproduce, create the following files:

generator_bug.pyx

def gen():
    yield 1

setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

ext_modules = [
    Extension('*', sources=['generator_bug.pyx'])
]

setup(
    name="generator_bug",
    ext_modules=cythonize(ext_modules),
    script_args=['build_ext'],
    options={'build_ext': {'inplace': True}}
)

Run python setup.py to build the extension module.

Run the following code from Python REPL:

from generator_bug import gen
try:
    1 / 0
except:
    for _ in gen():
        pass
    raise

The above code will not exit with a ZeroDivisionError, but a TypeError or RuntimeError, depending on whether the code is run using Python 2 or Python 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment