From 7e0c0cc45da8b15014654d067e4bd33f732368d9 Mon Sep 17 00:00:00 2001 From: Wim Pomp Date: Tue, 28 Jun 2022 11:08:37 +0200 Subject: [PATCH] - bugfix in parpool.get_newest - make TqdmMeter bar decrease when necessary --- parfor/__init__.py | 21 +++++++++++++++++---- setup.py | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/parfor/__init__.py b/parfor/__init__.py index ec1fd45..0fe72f0 100644 --- a/parfor/__init__.py +++ b/parfor/__init__.py @@ -114,12 +114,13 @@ class ExternalBar: class TqdmMeter(tqdm): """ Overload tqdm to make a special version of tqdm functioning as a meter. """ - def __init__(self, *args, **kwargs): + def __init__(self, iterable=None, desc=None, total=None, *args, **kwargs): self._n = 0 + self._total = total self.disable = False if 'bar_format' not in kwargs and len(args) < 16: kwargs['bar_format'] = '{desc}{bar}{n}/{total}' - super().__init__(*args, **kwargs) + super().__init__(iterable, desc, total, *args, **kwargs) @property def n(self): @@ -131,6 +132,16 @@ class TqdmMeter(tqdm): self._n = int(value) self.refresh() + @property + def total(self): + return self._total + + @total.setter + def total(self, value): + self._total = value + if hasattr(self, 'container'): + self.container.children[1].max = value + def __exit__(self, exc_type=None, exc_value=None, traceback=None): if not self.leave: self.n = self.total @@ -457,9 +468,11 @@ class Parpool: """ Request the newest key and result and delete its record. Wait if result not yet available. """ while len(self.tasks): self._get_from_queue() - for task in self.tasks: + for task in self.tasks.values(): if task.done: - return task.handle, task.result + handle, result = task.handle, task.result + self.tasks.pop(handle) + return handle, result def __delitem__(self, handle): self.tasks.pop(handle) diff --git a/setup.py b/setup.py index 14f26a4..d4c8fa7 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="parfor", - version="2022.5.0", + version="2022.6.0", author="Wim Pomp", author_email="wimpomp@gmail.com", description="A package to mimic the use of parfor as done in Matlab.",