PyThreadState_SetAsyncExc, PyErr_Clear and boost::python

G

gabriel.becedillas

I use PyThreadState_SetAsyncExc to stop a python thread but there are
situations when the thread doesn't stop and continues executing
normally. After some debugging, I realized that the problem is that
PyThreadState_SetAsyncExc was called when the thread was inside a
native extension, that for some reason calls PyErr_Clear. That code
happens to be inside boost::python.
I do need to stop the thread from executing Python code as soon as
possible (as soon as it returns from a native function is also
acceptable).
Because we have embedded Python's VM in our product, I'm thinking of
modifying PyErr_Clear() to return immediately if the thread was stopped
(we determine if the thread should stop using our own functions).
Example:

void PyErr_Clear(void)
{
if (!stop_executing_this_thread())
PyErr_Restore(NULL, NULL, NULL);
}

Does anybody see any problem with this approach ?, Does anybody have a
cleaner/better solution ?
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top