When will a blocking socket timeout?
<p>In the <a href="https://docs.python.org/2/library/socket.html#socket-objects" rel="nofollow">documentation</a> of the <code>socket</code> module it is written that:</p>

<blockquote>
  <p>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).</p>
</blockquote>

<p>Also, <a href="http://stackoverflow.com/a/25448603/501663">this SO answer</a> says:</p>

<blockquote>
  <p>By default, if no explicit timeout is set for the socket, it will
  block while doing so and eventually timeout, raising exception
  <code>socket.error: [Errno 110] Connection timed out</code></p>
</blockquote>

<p>My question is, in what situation a blocking socket (or is it the OS?) will raise a timeout? Can I have some control over this timeout, or is the only thing I can do is to catch the exception?</p>

<p><strong>EDIT</strong> Am I mixing the socket timeout with connection timeout? What is the difference?</p>

<p>If you not set, Operating System control the connect timeout. TCP/IP in blocking mode have three different timeout:</p>

<ul>
<li>Connect.</li>
<li>Read.</li>
<li>Write.</li>
</ul>

<p>For connect timeout and how TCP/IP connect work, you should checkout <strong>tcp_syn_retries</strong> sustem configuration value on Linux.</p>

<p><strong>EDIT</strong>: connect phrase contain some SYNC "handshake" packets while read/write phrase is "normal" packet. That is the difference.</p>

python sockets connection-timeout