code: def wait_for_winexe(host, port, username, password, timeout=900):
      '''
      Wait until winexe connection can be established.
      '''
      start = time.time()
      log.debug(
          'Attempting winexe connection to host %s on port %s',
          host, port
      )
      try_count = 0
      while True:
          try_count += 1
          try:
              # Shell out to winexe to check %TEMP%
              ret_code = run_winexe_command(
                  "sc", "query winexesvc", host, username, password, port
              )
              if ret_code == 0:
                  log.debug('winexe connected...')
                  return True
              log.debug('Return code was %s', ret_code)
          except socket.error as exc:
              log.debug('Caught exception in wait_for_winexesvc: %s', exc)
  
          if time.time() - start > timeout:
              return False
          time.sleep(1f wait_for_winexe(host, port, username, password, timeout=900):
      '''
      Wait until winexe connection can be established.
      '''
      start = time.time()
      log.debug(
          'Attempting winexe connection to host %s on port %s',
          host, port
      )
      try_count = 0
      while True:
          try_count += 1
          try:
              # Shell out to winexe to check %TEMP%
              ret_code = run_winexe_command(
                  "sc", "query winexesvc", host, username, password, port
              )
              if ret_code == 0:
                  log.debug('winexe connected...')
                  return True
              log.debug('Return code was %s', ret_code)
          except socket.error as exc:
              log.debug('Caught exception in wait_for_winexesvc: %s', exc)
  
          if time.time() - start > timeout:
              return False
          time.sleep(1)
docs: Wait until winexe connection can be established.