[Python-Dev] PyThreadState_SetAsyncExc bug? (original) (raw)

Tim Peters tim.peters at gmail.com
Fri Aug 11 13:49:53 CEST 2006


[tomer filiba]

while working on a library for raising exceptions in the context of another thread, i've come across a bug in PyThreadStateSetAsyncExc. if i raise an instance, sys.excinfo() confuses the exception value for the exception type, and the exception value is set None. if i raise the type itself, the interpreter creates an instance internally, but then i can't pass arguments to the exception.

That appears to be the way it was designed; i.e., AFAICT, it's working as intended. This follows from the code in ceval.c that raises the exception:

            if (tstate->async_exc != NULL) {
                x = tstate->async_exc;
                tstate->async_exc = NULL;
                PyErr_SetNone(x);
                Py_DECREF(x);
                why = WHY_EXCEPTION;
                goto on_error;
            }

PyErr_SetNone(x) there gives no possibility that setting an /instance/ could work as you hope -- x has to be an exception type, and tstate->async_exc is simply the exc argument that was passed to PyThreadState_SetAsyncExc().



More information about the Python-Dev mailing list