def _show_task_bar(self, pid=None, follow=False): """多行更新状态栏""" global output_list with output(output_type="list", initial_len=len(self._tasks), interval=0) as output_list: pool = [] for _pid, task in enumerate(self._tasks): if pid is not None and _pid != pid: # 如果指定了 pid 就只更新 pid 这个 task continue t = threading.Thread(target=self._show_task, args=(_pid, task, follow)) t.start() pool.append(t) [t.join() for t in pool]
def _show_task_bar(self, pid=None, follow=False): """多行更新状态栏""" global OUTPUT_LIST, TOTAL_TASKS with output(output_type="list", initial_len=len(self._tasks), interval=0) as OUTPUT_LIST: pool = [] TOTAL_TASKS = len(self._tasks) logger.debug(f"TaskManager: {TOTAL_TASKS=}") for _pid, task in enumerate(self._tasks): if pid is not None and _pid != pid: # 如果指定了 pid 就只更新 pid 这个 task continue t = Thread(target=self._show_task, args=(_pid, task, follow)) t.start() pool.append(t) [t.join() for t in pool]
from threading import Thread from time import time, sleep, monotonic from cloud189.cli.downloader import TaskType from cloud189.cli.utils import info, error, get_file_size_str, OS_NAME, get_upload_status from cloud189.cli.reprint import output # 修改了 magic_char from cloud189.api.utils import logger __all__ = ['global_task_mgr'] OUTPUT_LIST = output() TOTAL_TASKS = 0 class TimeoutExpired(Exception): pass def input_with_timeout(timeout=2): if OS_NAME == 'posix': # *nix import select import sys ready, _, _ = select.select([sys.stdin], [], [], timeout) if ready: try: return sys.stdin.readline().rstrip('\n') except OSError: return None raise TimeoutExpired