threads and exception in wxPython
Peter Hansen
peter at engcorp.com
Wed Nov 3 10:20:28 EST 2004
Peter Hansen wrote:
> >>> asyncexc = ctypes.pythonapi.PyThreadState_SetAsyncExc
> >>> exc = ctypes.py_object(ValueError)
> >>> asyncexc(t.id, exc)
> 1
> >>> t
> <T(Thread-2, started)>
>
> Hmm... clearly that's not enough, but perhaps closer.
But shortly after, trying to create a new thread, I got:
>>> t3 = T()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in __init__
File "c:\a\python23\lib\threading.py", line 384, in __init__
self.__block = Condition(Lock())
File "c:\a\python23\lib\threading.py", line 148, in Condition
return _Condition(*args, **kwargs)
File "c:\a\python23\lib\threading.py", line 154, in __init__
if lock is None:
ValueError
>>> t3 = T()
>>> t3
<T(Thread-4, started)>
>>> t3.id
5740
>>> t
<T(Thread-2, started)>
So the exception managed to get to the new thread, even though
I called SetAsyncExc *before* the thread was even created.
Now _that's_ what I call "asynchronous". ;-)
-Peter
More information about the Python-list
mailing list