title: Python's 2.7 socket.timeout behavior
body: <p>Below are two simple python functions. First tries to connect to <code>test.com</code> domain on 666 (host name is valid but port is not). Second tries to connect to <code>imap.mail.outlook.com</code> on port 993 (host name is valid, but looks like not for public use/access).</p>
  
  <pre><code>def fn_outlook(timeout):
      try:
          socket.create_connection(("imap.mail.outlook.com", 993), timeout=timeout)
      except socket.timeout:
          pass
  
  
  def fn_test(timeout):
      try:
          socket.create_connection(("test.com", 666), timeout=timeout)
      except socket.timeout:
          pass
  </code></pre>
  
  <p>And here are execution time for that function with different timeouts:</p>
  
  <pre><code>In [14]: %time fn_test(1)
  CPU times: user 644 µs, sys: 1.07 ms, total: 1.71 ms
  Wall time: 1 s
  
  In [15]: %time fn_test(2)
  CPU times: user 589 µs, sys: 1.15 ms, total: 1.74 ms
  Wall time: 2 s
  
  In [16]: %time fn_outlook(2)
  CPU times: user 838 µs, sys: 2.24 ms, total: 3.08 ms
  Wall time: 7.15 s
  
  In [17]: %time fn_outlook(4)
  CPU times: user 705 µs, sys: 1.18 ms, total: 1.88 ms
  Wall time: 12 s
  
  In [18]: %time fn_test(4)
  CPU times: user 483 µs, sys: 795 µs, total: 1.28 ms
  Wall time: 4.42 s
  </code></pre>
  
  <p>For <code>test.com</code> connection will timeout after the ~same time as was specified in <code>timeout</code> argument. But for <code>imap.mail.outlook.com</code> things are getting interesting -- socket connection ignores timeout argument. To be precise - not ignores, but rather always timeouts connection after some greater period of time.</p>
  
  <p>I may suppose that this behavior originates from <code>imap.mail.outlook.com</code> server,  not from socket module. </p>