SocketServer.ThreadingTCPServer - 程序重新启动后无法绑定到地址
作为 cannot-bind-to-address-after- 的后续操作socket-program-crashes,我的程序重新启动后收到此错误:
socket.error: [Errno 98] 地址已在使用中
在这种特殊情况下,程序不是直接使用套接字,而是启动自己的线程 TCP 服务器:
httpd = SocketServer.ThreadingTCPServer(('localhost', port), CustomHandler)
httpd.serve_forever()
如何修复此错误消息?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上述解决方案对我不起作用,但这个解决方案却有效:
The above solution didn't work for me but this one did:
在这种特殊情况下,当设置
allow_reuse_address
选项时,可以从 TCPServer 类调用.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
。所以我能够按如下方式解决它:无论如何,我认为这可能有用。 Python 3.0 中的解决方案略有不同
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