[Python-Dev] PyThreadState_SetAsyncExc bug?

tomer filiba tomerfiliba at gmail.com
Fri Aug 11 14:08:39 CEST 2006


so it should be fixed, or at least checked for conformness by the code.


-tomer

On 8/11/06, Tim Peters <tim.peters at gmail.com> wrote:
>
> [tomer filiba]
> > while working on a library for raising exceptions in the context
> > of another thread, i've come across a bug in PyThreadState_SetAsyncExc.
> > if i raise an instance, sys.exc_info() 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().
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060811/93b5d7e3/attachment.html 


More information about the Python-Dev mailing list