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


None yet
1 participant

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.

@scoder scoder added this to the 0.28 milestone Oct 29, 2017

@scoder scoder modified the milestone: 0.28 Nov 22, 2017

@scoder scoder added the help wanted label Nov 28, 2017

@scoder scoder added this to the 0.29 milestone Aug 18, 2018


This comment has been minimized.

Show comment
Hide comment

scoder Sep 15, 2018


Implemented in #2607.


scoder commented Sep 15, 2018

Implemented in #2607.

@scoder scoder closed this Sep 15, 2018

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