From a7577e683ff59f054dead4cfd68682f971626c3f Mon Sep 17 00:00:00 2001 From: Ivan Blagoev Topolsky Date: Fri, 11 Oct 2024 15:30:08 +0200 Subject: [PATCH] Progress bar when parallel processing --- lollipop/cli/deconvolute.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lollipop/cli/deconvolute.py b/lollipop/cli/deconvolute.py index adc63bd..4fffdab 100755 --- a/lollipop/cli/deconvolute.py +++ b/lollipop/cli/deconvolute.py @@ -156,13 +156,24 @@ def _deconvolute_bootstrap( # print the memory usage of the current location logging.info(f"memory usage: {loc_df.memory_usage().sum() / 1024**2} MB") + workerid = None + if n_cores != 1: + workerid = multiprocessing.current_process()._identity[0] - 1 + for b in ( - # Progress bar for sequential bootstrapping - trange(bootstrap, desc=location, leave=(len(locations_list) > 1)) - if bootstrap > 1 and n_cores == 1 - # No progress bar for parallel bootstrapping - else range(bootstrap) - if bootstrap > 1 and n_cores != 1 + ( + # Progress bar for sequential bootstrapping + trange(bootstrap, desc=location, leave=(len(locations_list) > 1)) + if n_cores == 1 + # Progress bar for parallel bootstrapping (at fixed per core position) + else trange( + bootstrap, + desc=f"core{workerid}: {location}", + leave=False, + position=workerid + 1, + ) + ) + if bootstrap > 1 # No bootstrapping else [0] ): @@ -683,7 +694,9 @@ def deconvolute( # Run the deconvolution in parallel else: # Create a pool of workers - with multiprocessing.Pool(processes=n_cores) as pool: + with multiprocessing.Pool( + processes=n_cores, initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),) + ) as pool: # Map the function to the arguments in parallel - choosing imap as objects are large instaed of pool.map all_deconv = list( tqdm(