title: BlockingIOError when trying to connect socket
body: <p>I am building a TCP Client in Python, that is supposed to try to connect to the server until a connection is established or the program is closed.
  I define a timeout on a blocking socket, but after the first attempt to connect I receive</p>
  
  <pre><code>BlockingIOError: [Errno 114] Operation already in progress
  </code></pre>
  
  <p>Here is a little code example:</p>
  
  <pre><code>import socket
  
  TCP_IP = '192.168.1.10'
  TCP_PORT = 7
  
  
  class TcpClient:
      def __init__(self):
          self.s = socket.socket(socket.AF_INET,  socket.SOCK_STREAM)
          self.s.settimeout(5)
  
      def connect(self):
          self.s.connect((TCP_IP,  TCP_PORT))
  
  
  if __name__ == "__main__":
      client = TcpClient()
      while True:
          try:
              client.connect()
          except socket.timeout:
              pass
  </code></pre>
  
  <p>If I understand the python documentation correctly, the timeout should occur when the connection attempt was not successful. That would mean that the socket is not trying to establish a connection anymore, but it seems like it still is.</p>
  
  <p>I tried to close the socket, too, but then I would need to create a new socket for every new connection attempt. I cannot believe that this is the perfect solution.</p>
  
  <p>I am open for any suggestions or help regarding this problem.
  Thank you!</p>