Exception Handling in TCPServer (was; Problem exiting application in Windows Console.)

Ant antroy at gmail.com
Thu Nov 9 07:02:05 EST 2006


Steve Holden wrote:
...
> First of all, five hour response time is a high expectation, you must be
> a Platinum customer :-)

I'm in the last week of my current job - start a new one on Monday, and
so I haven't got a great deal to do at the moment. Five hours is a
lifetime when you're staring at a newsgroup waiting for it to change
;-)

> Secondly, while a try/except catching all exceptions *is* unusual it's
> justifiable in a server context (though some logging and/or analysis
> certainly wouldn't go amiss).

True. And I'd expected that the exception ought to be passed to the
handle_error method so that something could be done with it there. This
morning however I discovered that Guido's been in his time machine
since yesterday and provided the very useful sys.exc_info() function
for this very purpose!

> Thirdly your "ugly hack" *could* be replaced by something cleaner with
> more analysis of the trace structure, but given how infrequently this
> code is going to run and the low probability that anything else will
> trigger the hook I'd be happy with it as it is. But that's just me ...

The sys.exc_info()  was what I was looking for it turns out, I can get
the exception type from that instead of trying to parse the stack
trace.

However:

Gabriel Genellina wrote:
...
> Replace serve_forever with your own loop checking an exit flag, and
> set the flag in your "quit.html" handler instead of sys.exit(0)

This is the approach I decided to go for. I found that RequestHandler
objects have a reference to its server that I can use to control the
server.

Thanks for the input chaps!




More information about the Python-list mailing list