[Python-Dev] PyThreadState_SetAsyncExc, PyErr_Clear and native extensions (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Fri May 12 07:16:09 CEST 2006


Gabriel Becedillas wrote:

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

I don't think there is a solution: asynchronous exceptions and thread cancellation just cannot work.

In the specific case, the caller of PyErr_Clear will continue its computation, instead of immediately leaving the function. To solve this specific problem, you would also have to give PyErr_Clear an int return code (whether or not the exception was cleared), and then you need to change all uses of PyErr_Clear to check for failure, and return immediately (after performing local cleanup, of course).

You then need to come up with a protocol to determine whether an exception is "clearable"; the new exception hierarchy suggests that one should "normally" only catch Exception, and let any other BaseException through. So PyErr_Clear should grow a flag indicating whether you want to clear just all Exceptions, or indeed all BaseExceptions.

Regards, Martin



More information about the Python-Dev mailing list