sys.traceback + thread

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Dec 9 15:08:04 CET 2003


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

> This is a thread's run method.
> 
>       def run(self):
>           try:
>               page=urllib.urlopen(base)
>               src=page.read()
>               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 
traceback.

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

-- 
Duncan Booth                                             duncan at rcp.co.uk
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