From b886a642be3e7486d487668b9319799b2d5a8551 Mon Sep 17 00:00:00 2001 From: adamhrv Date: Wed, 13 Feb 2019 00:13:26 +0100 Subject: clean up --- megapixels/commands/templates/multithreaded.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'megapixels') diff --git a/megapixels/commands/templates/multithreaded.py b/megapixels/commands/templates/multithreaded.py index fec3dac4..a9b287f8 100644 --- a/megapixels/commands/templates/multithreaded.py +++ b/megapixels/commands/templates/multithreaded.py @@ -2,9 +2,9 @@ import click @click.command() @click.option('-i', '--input', 'opt_fp_in', required=True, - help='Input file') + help='Input') @click.option('-o', '--output', 'opt_fp_out', required=True, - help='Output file') + help='Output') @click.option('-t', '--threads', 'opt_threads', default=4, help='Number of threads') @click.pass_context @@ -22,28 +22,27 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_threads): log.info('multithreaded template') # setup multithreading function - def pool_process(data_obj): + def pool_process(item): # threaded function - global parse_yt_page results = [] try: - # do something here with data_obj + # do something here with item except Exception as e: log.debug(f'Error: {e}') pbar.update(1) return results # setup multithreading data holds - items = [] # list of dicts to process - results = [] - num_items = len(items) + pool_items = [] # list of dicts to process + pool_results = [] + num_items = len(pool_items) # run the multithreading with progress bar pbar = tqdm(total=num_items) pool_process = partial(pool_process) pool = ThreadPool(opt_threads) with tqdm(total=num_items) as pbar: - results = pool.map(pool_process, media_items) + pool_results = pool.map(pool_process, pool_items) pbar.close() -- cgit v1.2.3-70-g09d2