multi-thread-example.py 749 B

1234567891011121314151617181920212223242526272829
  1. # coding: utf-8
  2. #
  3. # GIL limit python multi-thread effectiveness.
  4. # But is seems fine, because these operation have so many socket IO
  5. # So it seems no need to use multiprocess
  6. #
  7. import threading
  8. import adbutils
  9. from logzero import logger
  10. import uiautomator2 as u2
  11. def worker(d: u2.Device):
  12. d.app_start("io.appium.android.apis", stop=True)
  13. d(text="App").wait()
  14. for el in d.xpath("@android:id/list").child("/android.widget.TextView").all():
  15. logger.info("%s click %s", d.serial, el.text)
  16. el.click()
  17. d.press("back")
  18. logger.info("%s DONE", d.serial)
  19. for dev in adbutils.adb.device_list():
  20. print("Dev:", dev)
  21. d = u2.connect(dev.serial)
  22. t = threading.Thread(target=worker, args=(d,))
  23. t.start()