在 documentation socket
模块的内容如下:
Sockets are always created in blocking mode. In blocking mode, operations block until complete or the system returns an error (such as connection timed out).
此外,this SO answer说:
By default, if no explicit timeout is set for the socket, it will block while doing so and eventually timeout, raising exception
socket.error: [Errno 110] Connection timed out
我的问题是,在什么情况下阻塞套接字(或者是操作系统?)会引发超时?我可以控制这个超时,还是我唯一能做的就是捕获异常?
编辑 我是否将套接字超时与连接超时混合在一起?有什么区别?
最佳答案
如果您不设置它们,您的操作系统将控制连接超时。阻塞模式下的 TCP/IP 具有三种不同的超时:
- 连接。
- 阅读。
- 写。
要访问连接超时并了解 TCP/IP 连接的工作原理,您应该查看 Linux 上的 tcp_syn_retries 系统配置值。
编辑:连接短语包含一些SYNC“握手”数据包,而读/写短语是“正常”数据包。这就是区别。
关于python - 阻塞套接字什么时候会超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39386917/