code: def threadpool_map(task, args, message, concurrency, batchsize=1, nargs=None):
      
      import concurrent.futures
  
  
      njobs = get_njobs(nargs, args)
      show_progress = bool(message)
      batches = grouper(batchsize, tupleise(args))
      batched_task = lambda batch: [task(*job) for job in batch]
      if show_progress:
          message += ' (TP:{}w:{}b)'.format(concurrency, batchsize)
          pbar = setup_progressbar(message, njobs, simple_progress=True)
          pbar.start()
      with concurrent.futures.ThreadPoolExecutor(max_workers=concurrency) as executor:
          futures = []
          completed_count = 0
          for batch in batches:
              futures.append(executor.submit(batched_task, batch))
  
          if show_progress:
              for i, fut in enumerate(concurrent.futures.as_completed(futures), start=1):
                  completed_count += len(fut.result())
                  pbar.update(completed_count)
  
          else:
              concurrent.futures.wait(futures)
  
      if show_progress:
          pbar.finish()
  
      return flatten_list([fut.result() for fut in futures])
docs: Helper to map a function over a range of inputs, using a threadpool, with a progress meter