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. -- http://mail.python.org/mailman/listinfo/python-list