Skip to content

Instantly share code, notes, and snippets.

@gerritjandebruin
Last active March 31, 2021 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerritjandebruin/3aa036c8fe35a1b17d0bceb097e0e419 to your computer and use it in GitHub Desktop.
Save gerritjandebruin/3aa036c8fe35a1b17d0bceb097e0e419 to your computer and use it in GitHub Desktop.
import joblib
from tqdm.auto import tqdm
class ProgressParallel(joblib.Parallel):
def __init__(self, use_tqdm=True, total=None, desc=None, *args, **kwargs):
self._use_tqdm = use_tqdm
self._total = total
self._desc = desc
super().__init__(*args, **kwargs)
def __call__(self, *args, **kwargs):
with tqdm(disable=not self._use_tqdm, total=self._total,
desc=self._desc) as self._pbar:
return joblib.Parallel.__call__(self, *args, **kwargs)
def print_progress(self):
if self._total is None:
self._pbar.total = self.n_dispatched_tasks
self._pbar.n = self.n_completed_tasks
self._pbar.refresh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment