threads and exception in wxPython
Peter Hansen
peter at engcorp.com
Wed Nov 3 09:18:14 EST 2004
Antoon Pardon wrote:
> Op 2004-11-02, Zunbeltz Izaola schreef <zunbeltz at wm.lc.ehu.es.XXX>:
> Yes they can. Unfortunately in order to protect us from ourselves
> the powers that be, decided to only allow this to people who know C
> and have access to a C compilor.
>
> int PyThreadState_SetAsyncExc( long id, PyObject *exc)
There was a comment by someone that perhaps ctypes would allow
calling this directly. I don't know whether that's possible,
but if it is it's probably a fairly simple operation. I've
used ctypes in a fairly limited fashion, so I suspect it
would take me a while to figure it out, but this much works
anyway:
>>> import ctypes
>>> py = ctypes.dll.python23
<CDLL 'python23', handle 1e000000 at 9dfb98>
>>> py.PyThreadState_SetAsyncExc
<ctypes._CdeclFuncPtr object at 0x0098FB88>
Presumably the "id" above is a non-issue, but I think you
need to do something more complex to get a PyObject reference
to an exception in ctypes... not yet in my repertoire.
A quick test gave this when trying the brainless approach,
with t being a thread and exc a KeyboardInterrupt instance.
>>> py.PyThreadState_SetAsyncExc(id(t), byref(exc))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: expected CData instance
Anyone? Anyone? Bueller?
-Peter
More information about the Python-list
mailing list