================ @@ -501,70 +506,72 @@ def main(): # Build up a big regexy filter from all command line arguments. file_name_re = re.compile("|".join(args.files)) + files = {f for f in files if file_name_re.search(f)} - return_code = 0 + returncode = 0 try: - # Spin up a bunch of tidy-launching threads. - task_queue = queue.Queue(max_task) - # List of files with a non-zero return code. - failed_files = [] - lock = threading.Lock() - for _ in range(max_task): - t = threading.Thread( - target=run_tidy, - args=( - args, - clang_tidy_binary, - export_fixes_dir, - build_path, - task_queue, - lock, - failed_files, - ), + semaphore = asyncio.Semaphore(max_task) + tasks = [ + run_with_semaphore( + semaphore, + run_tidy, + args, + f, + clang_tidy_binary, + export_fixes_dir, + build_path, ) - t.daemon = True - t.start() - - # Fill the queue with files. - for name in files: - if file_name_re.search(name): - task_queue.put(name) - - # Wait for all threads to be done. - task_queue.join() - if len(failed_files): - return_code = 1 - + for f in files + ] + + for i, coro in enumerate(asyncio.as_completed(tasks)): + name, process_returncode, stdout, stderr = await coro + if process_returncode != 0: + returncode = 1 + if process_returncode < 0: + stderr += f"{name}: terminated by signal {-process_returncode}\n" + print(f"[{i + 1}/{len(files)}] {name}") ---------------- 5chmidti wrote:
It would look even nicer if the first number was printed with the width of the second number, i.e.: ``` [ 3/15] ... [15/15] ``` That way, the position of the second number and the command(/file) does not shift when the next power of ten is reached. ```python i = 4 num_files = 15 print("[{0: >{1}}/{2}]".format(i+1,len(f"{num_files}"), num_files)) print(f'[{i+1: >{len(f"{num_files}")}}/{num_files}]') ``` https://github.com/llvm/llvm-project/pull/89490 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits