-
-
Save varunpant/1c67a5e4cc9aa483fa2ad2e27afc4c44 to your computer and use it in GitHub Desktop.
Revisions
-
tekknolagi revised this gist
Feb 22, 2024 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,8 @@ def func(repo_name): log(repo_name, "Running tests") randsleep() log(repo_name, f"Result in {repo_name}.json") with terminal_lock: del last_output_per_process[repo_name] repos = [f"repo{letter}" for letter in string.ascii_uppercase] -
tekknolagi revised this gist
Feb 22, 2024 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,7 +44,6 @@ def func(repo_name): randsleep() log(repo_name, f"Result in {repo_name}.json") del last_output_per_process[repo_name] repos = [f"repo{letter}" for letter in string.ascii_uppercase] -
tekknolagi revised this gist
Feb 22, 2024 . 1 changed file with 23 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,21 +2,33 @@ import multiprocessing import random import string import time def fill_output(): to_fill = num_lines - len(last_output_per_process) for _ in range(to_fill): print() def clean_up(): for _ in range(num_lines): print("\x1b[1A\x1b[2K", end="") # move up cursor and delete whole line def log(repo_name, *args): with terminal_lock: last_output_per_process[repo_name] = " ".join(str(arg) for arg in args) clean_up() sorted_lines = last_output_per_process.items() for repo_name, last_line in sorted_lines: print(f"{repo_name}: {last_line}") fill_output() def randsleep(): time.sleep(random.randint(1, 2)) def func(repo_name): @@ -35,15 +47,14 @@ def func(repo_name): return f"{repo_name} done" repos = [f"repo{letter}" for letter in string.ascii_uppercase] num_procs = multiprocessing.cpu_count() num_lines = min(len(repos), num_procs) with multiprocessing.Manager() as manager: last_output_per_process = manager.dict() terminal_lock = manager.Lock() # Make space for our output fill_output() with multiprocessing.Pool(num_procs) as pool: pool.map(func, repos, chunksize=1) clean_up() -
tekknolagi revised this gist
Feb 22, 2024 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,10 +38,11 @@ def func(repo_name): with multiprocessing.Manager() as manager: last_output_per_process = manager.dict() terminal_lock = manager.Lock() # Make space for our output numprocs = multiprocessing.cpu_count() for _ in range(numprocs): print() with multiprocessing.Pool() as pool: for result in pool.imap( func, ["repoA", "repoB", "repoC", "repoD"], chunksize=1 ): -
tekknolagi revised this gist
Feb 22, 2024 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,15 +31,17 @@ def func(repo_name): log(repo_name, "Running tests") randsleep() log(repo_name, f"Result in {repo_name}.json") del last_output_per_process[repo_name] return f"{repo_name} done" with multiprocessing.Manager() as manager: last_output_per_process = manager.dict() terminal_lock = manager.Lock() numprocs = 2 with multiprocessing.Pool(numprocs) as pool: for _ in range(numprocs): print() for result in pool.imap( func, ["repoA", "repoB", "repoC", "repoD"], chunksize=1 ): -
tekknolagi created this gist
Feb 22, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ #!/usr/bin/env python import multiprocessing import random import time def log(repo_name, *args): last_output_per_process[repo_name] = " ".join(str(arg) for arg in args) with terminal_lock: sorted_lines = last_output_per_process.items() for _ in sorted_lines: print("\x1b[1A\x1b[2K", end="") # move up cursor and delete whole line for repo_name, last_line in sorted_lines: print(f"{repo_name}: {last_line}") def randsleep(): time.sleep(random.randint(1, 5)) def func(repo_name): log(repo_name, "Starting") randsleep() log(repo_name, "Installing") randsleep() log(repo_name, "Building") randsleep() log(repo_name, "Instrumenting") randsleep() log(repo_name, "Running tests") randsleep() log(repo_name, f"Result in {repo_name}.json") # Note: To limit the output to the number of active processes, del from # last_output_per_process. return f"{repo_name} done" with multiprocessing.Manager() as manager: last_output_per_process = manager.dict() terminal_lock = manager.Lock() with multiprocessing.Pool(2) as pool: for result in pool.imap( func, ["repoA", "repoB", "repoC", "repoD"], chunksize=1 ): pass