Oto mój kod, aby uruchomić serwer:pyton już w użyciu, ale adres tcpserver zamknąć serwer i używam `allow_reuse_address`
class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
#....
PORT = 8089
httpd = SocketServer.TCPServer(("", PORT), MyRequestHandler)
httpd.allow_reuse_address = True
print "Serving forever at port", PORT
try:
httpd.serve_forever()
except:
print "Closing the server."
httpd.server_close()
raise
Jednak to, co się dzieje:
^CClosing the server.
Traceback (most recent call last):
File "server.py", line 118, in <module>
self.send_error(400, "Unimplemented GET command: %s" % (self.path,))
File "/home/claudiu/local/lib/python2.6/SocketServer.py", line 224, in serve_forever
r, w, e = select.select([self], [], [], poll_interval)
KeyboardInterrupt
(.virtualenv)[email protected]:~/xxx$ python server.py
Traceback (most recent call last):
File "server.py", line 122, in <module>
httpd = SocketServer.TCPServer(("", PORT), MyRequestHandler)
File "/home/claudiu/local/lib/python2.6/SocketServer.py", line 402, in __init__
self.server_bind()
File "/home/claudiu/local/lib/python2.6/SocketServer.py", line 413, in server_bind
self.socket.bind(self.server_address)
File "<string>", line 1, in bind
socket.error: [Errno 98] Address already in use
Dlaczego ? Zamykam serwer i ustawię allow_reuse_address
na True ... Using python 2.6.8.
a nie wielki cytat. Port * nadal * występuje * w stanie TIME_WAIT. Nie ma gniazda i nie można słuchać. – EJP
Rozumiem, ale chciałem wiedzieć, dlaczego moje rozwiązania (ustaw 'allow_reuse_address' i zamknij gniazdo podczas zamykania) nie naprawiły tego. – Claudiu