SocketServer clean shutdown from signal
Jeffrey W. Collyer
jwc3f at spammenolikey.Virginia.EDU
Tue Jul 31 15:59:26 EDT 2001
I'm using SocketServer.StreamRequestHandler to write a multithreaded network
daemon. In normal useage it will serve requests forever and never shut down.
However, I want to be able to send the server a kill signal and immediately
restart it on the same port. (this is under Unix, specifically Solaris).
I built the signal handler outside of the class, and I don't seem to be able
to cleanly release the socket when the server gets a kill. If I have a
client connected to the server, when I send the kill, the socket goes into
TIME_WAIT no matter what I try.
Is there anyway around this?
I have something like this :
----
# set up signal handler
def sighandler(signum,frame):
# my stuff here
os._exit(0)
signal.signal(signal.SIGINT,sighandler)
class MyHandler(SocketServer.StreamRequestHandler):
def main():
host='' # localhost name
port=31752 # local port number
# create the Threading server
server = SocketServer.ThreadingTCPServer( (host,port), MyHandler)
server.allow_reuse_address=1
server.serve_forever()
----
I can't seem to access the socket object of the Myhandler instance server
inside the signal handler. If I do a
server.socket.close()
I get an exception.
Any ideas?
--
Jeff
More information about the Python-list
mailing list