Skip to content

Commit

Permalink
Merge pull request #7 from analysiscenter/fix_pbar
Browse files Browse the repository at this point in the history
Fix pbar
  • Loading branch information
alexanderkuvaev authored Feb 21, 2024
2 parents 09bc08e + e6f006c commit aa190b5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions segfast/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
""" !!. """
from functools import partial
from concurrent.futures import Future, Executor


try:
from batchflow import Notifier
except ImportError:
try:
from functools import partial
from tqdm.auto import tqdm
def Notifier(pbar, *args, **kwargs):
""" Progress bar. """
if pbar:
return tqdm(*args, **kwargs)
return lambda iterator: iterator

class Notifier:
""" tqdm notifier. """
def __init__(self, bar=False, total=None, **kwargs):
if 'frequency' in kwargs:
kwargs['miniters'] = kwargs.pop('frequency')
self.pbar = partial(tqdm, disable=not bar, total=total, **kwargs)

def __call__(self, iterator):
return self.pbar(iterator)

def __enter__(self):
return self.pbar()

def __exit__(self, _, __, ___):
pass

except ImportError:
class Notifier:
""" Dummy notifier. """
Expand Down

0 comments on commit aa190b5

Please sign in to comment.