python - 阻塞套接字什么时候会超时?

标签 python sockets connection-timeout

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/

相关文章:

python - 您能否使 python 脚本在导入时的行为与直接运行时的行为不同?

c - 跟踪客户端-服务器事务 - c 中的套接字

索引期间 Solr 连接超时?

javascript - 浏览器超时 : the server at example. com 响应时间太长

python - 将字符串解析为元组列表

python - 为什么环境 ['wsgi.input' ].read() 即使 PEP-3333 允许也会阻塞?

python - 在 Pandas DataFrame 中创建带有集合的新列

sockets - Netty并发和 "Connection reset by peer"

linux - Server单个端口(socket)最大并发连接数

PHP MySQL 设置连接超时