docs: def identify_window(pid, text):
      """Identify the app associated with a window."""
      proc = None
      path = None
      uas = Session.query(UserApp).filter(UserApp.window_text == text)
      nontext = Session.query(UserApp).filter(UserApp.window_text == None)
      if uas.count():
          proc = psutil.Process(pid)
          try:
              path = proc.exe()
          except psutil.AccessDenied:
              path = proc.name()
          logger.debug("Trying to identify app, path=%s", path)
          app = uas.filter(UserApp.path == path).first()
          if app:
              return app, proc
      if nontext.count():
          if proc == None:
              proc = psutil.Process(pid)
              path = proc.exe()
              app = nontext.filter(UserApp.path == path).first()
              if app:
                  return app, proc
      return None, None