socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use')

Laszlo Nagy gandalf at shopzeus.com
Tue Jan 27 10:49:03 CET 2009


I have a program that uses socket.bind() and socket.listen() frequently. 
After that program stops, it is not able to bind() again for a while:

 File "/home/gandalf/Python/Lib/orb/accesspoints/srvtcp.py", line 27, in 
__init__
    self.serversocket.bind((self.listen_address,self.port))
  File "<string>", line 1, in bind
socket.error: (48, 'Address already in use')


The problem with this, is that this server program SOMETIMES need to be 
restarted very quickly. I tried to find the solution in the socket 
module. But there is no "socket.unbind" or "socket.unlisten". How can I 
tell the OS that I do not want to listen on that address anymore, so 
other programs can bind on it immediatelly?

(Yes I know that I can use setsockopt to allow listening multiple 
sockets on the same address, but this is NOT what I need...)

Thanks,

   Laszlo




More information about the Python-list mailing list