openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.38k stars 1.37k forks source link

catch exception when _run_watchers #898

Closed twoyang0917 closed 5 months ago

twoyang0917 commented 1 year ago
Traceback (most recent call last):
  File "/Users/coco/.rye/py/cpython@3.8.16/install/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Users/coco/.rye/py/cpython@3.8.16/install/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/watcher.py", line 227, in _watch_forever
    triggered = self.run()
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/watcher.py", line 239, in run
    return self._run_watchers(source=source)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/watcher.py", line 246, in _run_watchers
    source = source or self._dump_hierarchy()
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/watcher.py", line 175, in _dump_hierarchy
    return self._d.dump_hierarchy()
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/retry/api.py", line 73, in retry_decorator
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/retry/api.py", line 33, in __retry_internal
    return f()
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 978, in dump_hierarchy
    content = self.jsonrpc.dumpWindowHierarchy(compressed, None)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 479, in __call__
    return self.server._jsonrpc_retry_call(self.method, params,
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 486, in _jsonrpc_retry_call
    return self._jsonrpc_call(*args, **kwargs)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 513, in _jsonrpc_call
    res = self.http.post("/jsonrpc/0",
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 210, in request
    self.__client._is_agent_alive():
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 586, in _is_agent_alive
    return bool(self._get_agent_version())
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 570, in _get_agent_version
    url = self.path2url("/version")
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 301, in path2url
    return urlparse.urljoin(self._get_atx_agent_url(), path)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/uiautomator2/__init__.py", line 282, in _get_atx_agent_url
    lport = self._adb_device.forward_port(
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/adbutils/_device.py", line 249, in forward_port
    self.forward("tcp:" + str(local_port), remote)
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/adbutils/_device.py", line 239, in forward
    self.open_transport(":".join(args))
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/adbutils/_device.py", line 90, in open_transport
    c.check_okay()
  File "/Users/coco/toy/.venv/lib/python3.8/site-packages/adbutils/_adb.py", line 134, in check_okay
    raise AdbError(self.read_string_block())
adbutils.errors.AdbError

exception above cause watcher thread exit