code: def wait_for_net_service(server, port, timeout=None, poll_interval=0.1):
      
      import socket
      import errno
  
      s = socket.socket()
      if timeout:
          from time import time as now
          # time module is needed to calc timeout shared between two exceptions
          end = now() + timeout
  
      while True:
          try:
              if timeout:
                  next_timeout = end - now()
                  if next_timeout < 0:
                      return False
                  else:
                      s.settimeout(next_timeout)
  
              s.connect((server, port))
  
          except socket.timeout as err:
              # this exception occurs only if timeout is set
              if timeout:
                  return False
  
          except Exception as err:
              # catch timeout exception from underlying network library
              # this one is different from socket.timeout
              if not isinstance(err.args, tuple) or err.args[0] != errno.ETIMEDOUT:
                  pass  # raise
          else:
              s.close()
              return True
          time.sleep(poll_interval)
docs: Wait for network service to appear
          @param timeout: in seconds, if None or 0 wait forever
          @return: True of False, if timeout is None may return only True or
                   throw unhandled network exception