[issue1779233] PyThreadState_SetAsyncExc and the main thread

Antoine Pitrou report at bugs.python.org
Sun Oct 18 20:19:10 CEST 2009


Antoine Pitrou <pitrou at free.fr> added the comment:

The following works (2.6 and trunk):

import ctypes, thread
ctypes.pythonapi.PyThreadState_SetAsyncExc(
    ctypes.c_long(thread.get_ident()),
    ctypes.py_object(ZeroDivisionError))
for i in range(1000): pass


The thing to remember is that PyThreadState_SetAsyncExc() is
asynchronous and doesn't guarantee that the exception will be raised
timely (that's why I added a small busy loop above).

----------
nosy: +pitrou

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1779233>
_______________________________________


More information about the Python-bugs-list mailing list