[Karrigell-main] Signal Handling
Brought to you by:
quentel
From: Gabriele G. <g.g...@te...> - 2004-06-18 09:52:20
|
This is the last part of Karrigell.py I've modified: server=None import signal def signal_handler (signal,frame): global server # How the hell do I gracefully stop The SocketServer ? server.close() server.finish() # kill -9 signal.signal(signal.SIGKILL, signal_handler) # kill -15 signal.signal(signal.SIGTERM, signal_handler) # kill -1 signal.signal(signal.SIGHUP, signal_handler) # ctrl+c signal.signal(signal.SIGINT, signal_handler) # Launch the server import SocketServer server=SocketServer.TCPServer(('', conf.PORT), RequestHandler) server.serve_forever() # ----- eof ---- The actual problem is that when Karrigell is killed or stopped the socket keeps the port open for one/two minutes (depending by the OS'sTCP/IP implementation). Is there a way to trap a kill signal and the close the listening socket gracefully ? Cheers. |