As a follow-up to cannot-bind-to-address-after-socket-program-crashes, I was receiving this error after my program was restarted:
socket.error: [Errno 98] Address already in use
In this particular case, instead of using a socket directly, the program is starting its own threaded TCP server:
httpd = SocketServer.ThreadingTCPServer(('localhost', port), CustomHandler)
httpd.serve_forever()
How can I fix this error message?
The above solution didn't work for me but this one did:
In this particular case,
.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
may be called from the TCPServer class when theallow_reuse_address
option is set. So I was able to solve it as follows:Anyway, thought this might be useful. The solution will differ slightly in Python 3.0