fixing progress bars with log files

This commit is contained in:
Mayeul Aubin 2025-03-17 13:54:54 +01:00
parent 32fa9a5afb
commit 942f775425
3 changed files with 23 additions and 2 deletions

View file

@ -22,6 +22,9 @@ def main_scola(parsed_args):
tile_bar = tqdm(total=nboxes_tot, desc="sCOLA", unit="box", disable=(parsed_args.verbose!=1)) # The progress bar cannot work if there are print statements in the loop
for b in range(1,nboxes_tot+1):
if not isfile(card_dict["OutputTilesBase"]+str(b)+".h5") or parsed_args.force:
if isfile(log_file+f"_{b}"): # Remove the preexisting log file to allow for the progress_bar to be run normally
from os import remove
remove(log_file+f"_{b}")
if parsed_args.verbose > 1:
print_message(f"Running box {b}/{nboxes_tot}.", 2, "scola", verbose=parsed_args.verbose)
command_args = ["scola", paramfile, log_file, "-b", str(b)]
@ -72,6 +75,10 @@ def main_scola(parsed_args):
print_message(f"Submitting scola job to SLURM.", 1, "scola", verbose=parsed_args.verbose)
command_args = ["sbatch", slurm_script]
for b in range(1,nboxes_tot+1):
if isfile(log_file+f"_{b}"): # Remove the preexisting log file to allow for the progress_bar to be run normally
os.remove(log_file+f"_{b}")
if parsed_args.verbose < 2:
subprocess.run(command_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
@ -105,6 +112,10 @@ def main_scola(parsed_args):
print_message(f"Submitting scola job to SLURM.", 1, "scola", verbose=parsed_args.verbose)
command_args = ["sbatch", slurm_script]
for b in range(missing_tiles[0],missing_tiles[1]+1):
if isfile(log_file+f"_{b}"): # Remove the preexisting log file to allow for the progress_bar to be run normally
os.remove(log_file+f"_{b}")
if parsed_args.verbose < 2:
subprocess.run(command_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else: