Exiting SocketServer: socket.error: (98, 'Address already in use')
Magnus Lycka
lycka at carmen.se
Tue May 31 07:15:38 EDT 2005
Thank's a lot Andrew and Dennis.
Andrew Dalke wrote:
> You can set the class variable "allow_reuse_address = True" in
> your derived ExitableSocketServer to get the behaviour you
> expect, at the expense of some problems mentioned in the
> above URL.
Ok. I added a STOP message to my protocol, so now the client
shuts down the socket first (when it has read the STOP), and
then it seems to work much better. What I did, in case the
client gets behind, was this in my handle method: I send a STOP
message repeatedly with a delay. When the client gets the first
one, it will close the socket, and I will get an exception the
next time I try to send. This seems to work well, without
(I hope) introducing any new potential problems.
...
delay = 1
print "No more data to serve. Send STOP message."
print "Waiting for client to close socket."
while 1:
try:
self.request.send("STOP\n")
time.sleep(delay)
print '.'
finally:
sys.exit()
More information about the Python-list
mailing list