sys.traceback + thread

Duncan Booth duncan at
Tue Dec 9 15:08:04 CET 2003

fowlertrainer at wrote in news:mailman.264.1070976113.16879.python-
list at

> This is a thread's run method.
>       def run(self):
>           try:
>               page=urllib.urlopen(base)
>               page=None
>               self.ResultCode=0
>               self.ResultSrc=src
>           except:
>               self.ResultSrc="An error occured"+
>                the exception's errormessage !!!
>               self.ResultCode=1
> I use the traceback module in one threaded application.
> But I don't use it in multiple threaded app.
> What can I use/how can I do in except section to get the exception's
> message ?
> Please help me.

Call sys.exc_info() to get the current exception details, then use the 
traceback module to format the information as you require. Or you could 
call traceback.print_exc() if you just want to display the exception and 

sys.exc_info() and print_exc() are both thread safe.

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list