多线程拉取工具
| 107 | |
| 108 | |
| 109 | class ThreadRunner(object): |
| 110 | """多线程拉取工具""" |
| 111 | |
| 112 | def __init__(self): |
| 113 | """ |
| 114 | :param error_list: 收集子线程异常,返回给主线程 |
| 115 | """ |
| 116 | self._error_list = [] |
| 117 | self._process_bar = None |
| 118 | |
| 119 | def __load_tool_callback__(self, tool_info): |
| 120 | # LogPrinter.info("初始化工具: %s" % tool_info["tool_dirname"]) |
| 121 | try: |
| 122 | ToolCommonLoader.load_tool(tool_info["load_type"], tool_info["tool_dirpath"], |
| 123 | tool_info["copy_from"], tool_info["git_url"], |
| 124 | scm_auth_info=tool_info.get("auth_info")) |
| 125 | except Exception as err: |
| 126 | LogPrinter.error(f"load tool err: {str(err)}") |
| 127 | self._error_list.append(err) |
| 128 | |
| 129 | # 更新进度条 |
| 130 | self._process_bar.update(1) |
| 131 | |
| 132 | def run(self, tool_lists): |
| 133 | tool_name_list = [info["tool_dirname"] for info in tool_lists] |
| 134 | tools_count = len(tool_name_list) |
| 135 | # LogPrinter.info("Initialize tools: %s" % ", ".join(tool_name_list)) |
| 136 | LogPrinter.info(f"Initing {tools_count} tools, please wait a minute ...") |
| 137 | |
| 138 | self._process_bar = tqdm(total=tools_count, desc="[Tools init]", ncols=100) |
| 139 | |
| 140 | min_t = 20 |
| 141 | max_t = 1000 |
| 142 | callback_queue = CallbackQueue(min_threads=min_t, max_threads=max_t) |
| 143 | for tool_info in tool_lists: |
| 144 | callback_queue.append(self.__load_tool_callback__, tool_info) |
| 145 | callback_queue.wait_for_all_callbacks_to_be_execute_and_destroy() |
| 146 | self._process_bar.close() |
| 147 | return self._error_list |
| 148 | |
| 149 | |
| 150 | class ConfigUtil(object): |