Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exception state stack in Py3.7 #1958

scoder opened this issue Oct 29, 2017 · 1 comment

Support exception state stack in Py3.7 #1958

scoder opened this issue Oct 29, 2017 · 1 comment


Copy link

scoder commented Oct 29, 2017

CPython 3.7 adds a new exception state stack for generators:


typedef struct _err_stackitem {
    /* This struct represents an entry on the exception stack, which is a 
     * per-coroutine state. (Coroutine in the computer science sense, 
     * including the thread and generators).
     * This ensures that the exception state is not impacted by "yields"
     * from an except handler.
    PyObject *exc_type, *exc_value, *exc_traceback;

    struct _err_stackitem *previous_item;

} _PyErr_StackItem;

It is used like this:

     gen->gi_running = 1;
+    gen->gi_exc_state.previous_item = tstate->exc_info;
+    tstate->exc_info = &gen->gi_exc_state;
     result = PyEval_EvalFrameEx(f, exc);
+    tstate->exc_info = gen->gi_exc_state.previous_item;
+    gen->gi_exc_state.previous_item = NULL;
     gen->gi_running = 0;


Cython should do the same thing in its coroutines in Py3.7+.
The previous Cython changes in #1956 and the problem description in #1955 are incomplete.

Copy link
Contributor Author

scoder commented Sep 15, 2018

Implemented in #2607.

@scoder scoder closed this as completed Sep 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant