Exiting a program from within an object method.

Benjamin Scherrey scherrey at innoverse.com
Thu Jan 4 10:42:29 EST 2001


        I've written a small python program that instantiates an object which 
inherits from SocketServer.BaseRequestHandler. The __main__ function starts 
this thing up with the serve_forever() method. Inside the handle() method 
of my object I check for a command to shutdown and, if received, call 
sys.exit(0). All this does is generate a SystemExit exception and does not 
terminate my program. Even if I wrap the call to serve_forever() with a 
try: except: block, the exception is not caught. I presume because the 
object's handle() method is possibly being executed in a child thread and 
python must not support cross thread exception handling (I'm not 
instantiating any threads explicitly, I'm assuming that the 
BaseRequestHandler is doing this internally)? 

        What's a simple way to have my object exit the application cleanly? 

        thanx & later,

                Ben Scherrey




More information about the Python-list mailing list