在 python 中,当在套接字对象上使用 select.select 时,我应该如何处理最终出现在错误列表中的套接字?
read, write, error = select.select(sockets, sockets, sockets, 60.0)
如果错误列表中出现某些内容,建议采取什么措施?
read, write, error = select.select(sockets, sockets, sockets, 60.0)
What is recommended if something ends up in the error list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我知道的操作系统上,除了尝试关闭套接字(这可能会引发异常,因此请务必使用
try
/尝试周围除外
)。您知道这些套接字代表的连接已异常终止,并且可能需要写入一些相关日志信息,向用户显示问题等。在某些情况下,尝试再次建立这些连接可能是合适的(这当然可能会失败,具体取决于遇到的异常情况,因此请为此做好准备)。On the operating systems I know, there's nothing you can do with the sockets suffering "exceptional conditions", except trying to close them (which may raise an exception, so be sure to use a
try
/except
around the attempt). You know that the connections those sockets stood for have terminated abnormally, and may want to write some log information about that, show the problem to the user, or the like. In some situations, it may be appropriate to try to establish those connections again (this may of course fail, depending on what exceptional condition was encountered, so be prepared for that).