Exiting threads silently

Peter Hansen peter at engcorp.com
Tue Feb 12 08:05:59 EST 2002


Michael Bauer wrote:
> 
> What happens is the error page gets displayed correctly in the browser, but
> therad.exit() dumps following exception to the console:
> 
> ----------------------------------------
> Exception happened during processing of request from ('127.0.0.1', 40400)
> Traceback (most recent call last):
>   File "/usr/lib/python2.2/SocketServer.py", line 458, in
> process_request_thread
>     self.finish_request(request, client_address)
>   File "/usr/lib/python2.2/SocketServer.py", line 253, in finish_request
>     self.RequestHandlerClass(request, client_address, self)
>   File "/usr/lib/python2.2/SocketServer.py", line 514, in __init__
>     self.handle()
>   File "/home/fake/devel/iowl/pProxy/cProxyHandler.py", line 170, in handle
>     server, client = self.Connect(host, port)
>   File "/home/fake/devel/iowl/pProxy/cProxyHandler.py", line 346, in Connect
>     self.error(200, 'Error connecting to "%s" (%s)' % (host, err))
>   File "/home/fake/devel/iowl/pProxy/cProxyHandler.py", line 504, in error
>     thread.exit()
> SystemExit
> ----------------------------------------
> 
> Anybody has an idea how i can exit silently?

The docs (i.e. the SocketServer source) suggest that the default 
error handler will print a traceback and continue when an exception
is raised.  Try overriding handle_error() on your server class,
catch SystemExit separately, and re-raise it if you get it.

(There may be better ways of handling this.  I'm no expert.)

-Peter



More information about the Python-list mailing list