Passing Exceptions Across Threads

Adam Mullins adam.l.m at gmail.com
Wed Apr 26 01:15:55 EDT 2006


Hello, I'm writing a physics simulator back-end with a built-in,
threaded server that for the moment is quite simple. I've faced a few
problems in writing this code, however, as it's the first time I've
played with threading. For the moment, everything works decently, but I
need (or rather, want) a method for passing caught exceptions in
sub-threads to the main thread to be raised there. Although this
solution isn't the only one, I feel it will be the most elegant (the
thread/class will be called inside the main module within a try/except
structure, which makes the program a bit more modular, in my opinion,
and cleaner).

Here is my code so far:
http://rafb.net/paste/results/UESOWB24.html

You can see near the top where I clumsily tried to a hack a function
into threading._MainThread, in the hopes that if it were called from a
sub-thread it would execute in the main thread. This is seemingly not
so.

Many thanks for any help.




More information about the Python-list mailing list