stopping servers

Arkaitz abitorika at openworld.co.uk
Tue Aug 15 07:53:20 EDT 2000


Hi all,

I'm writing a TCP server by subclassing SocketServer.TCPServer, and I
can't find a way of shutting down the server cleanly. I'm trying to do
it by handling a signal like SIGINT with a code like this:

def handler(signum, frame):
    global server
    print "Stopping server..."
    try:
        proxy = None
        exit
    except Exception, e:
        exit

This gives me a socket.error when I try to do the first "exit" that is
caught, but the second seems to raise it as well, and this one just
outputs the traceback to stdout.
Does anyone know how to shut up properly the server? It's running inside
of the serve_forever infinite loop.

Thanks,

Arkaitz.




More information about the Python-list mailing list