threads and exception in wxPython

Antoon Pardon apardon at forel.vub.ac.be
Wed Nov 3 08:25:30 EST 2004


Op 2004-11-02, Zunbeltz Izaola schreef <zunbeltz at wm.lc.ehu.es.XXX>:
>
> Hi,
>
> I've an wxPython windows that creates a thread. An object of this
> thread raised an exception and i want to cach it in the main thread,
> that of the windows (I want this becouse the first implementation
> doesn't use thread). I know that exception can not be pass between 
> thread.

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.

from http://docs.python.org/api/threads.html:

  int PyThreadState_SetAsyncExc( long id, PyObject *exc)
      Asynchronously raise an exception in a thread. The id argument is
      the thread id of the target thread; exc is the exception object to
      be raised. This function does not steal any references to exc. To
      prevent naive misuse, you must write your own C extension to call
      this. Must be called with the GIL held. Returns the number of thread
      states modified; if it returns a number greater than one, you're in
      trouble, and you should call it again with exc set to NULL to revert
      the effect. This raises no exceptions. New in version 2.3. 


I find this most unfortunate, because in my view being naive is
not in opposition with easily knowing to write a C extention.
I also find it a bad idea to force people to know C for a feature
which has some perfect uses for people who don't know C and normally
have no need to know C.

-- 
Antoon Pardon



More information about the Python-list mailing list