这里是我的代码来运行服务器:蟒蛇TCPSERVER地址我关闭服务器,我用`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
然而,这是发生了什么:
^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
为什么?我关闭服务器并将allow_reuse_address
设置为True ...使用python 2.6.8。
不是一个伟大的引用。 *端口*在TIME_WAIT状态下仍然存在*。没有插座,也没有听。 – EJP 2013-03-07 05:12:17
我明白了,但我想知道为什么我的解决方案(在关闭时设置'allow_reuse_address'并关闭套接字)没有修复它。 – Claudiu 2013-03-07 15:21:58