多设备执行同一个单元测试或性能测试或稳定性测试情况,如果遍历下发,则需要等前者执行完毕后才能执行后者,等待时间太久
1、多线程
python3import threading t_list = [] for serial in serial_list: app_interact = AppInteract(serial) # 加到线程 t = threading.Thread(target=app_interact.get_crash, args=(result_dict,)) t_list.append(t) for t in t_list: # t.setDaemon(True) t.start() for t in t_list: t.join()
2、异步
python3import asyncio async def handle_device_apps_info(self, udid: str) -> dict: """异步获取第三方应用的具体信息""" app_list = self.handle_device_app_list(udid) apps_info = {} # 创建异步任务列表 tasks = [self.app_info(udid, app) for app in app_list] # 并发执行所有任务 results = await asyncio.gather(*tasks) # 处理结果 for app_info in results: if app_info: apps_info[app_info['package_name']] = app_info return apps_info
外层使用
python3apps_info = await hm_controller.handle_device_apps_info(udid)
对比发现,串行可能是N个应用*2秒,现在直接压缩到2秒内了
本文作者:lixf6
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!