Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maximum_refresh_time to progress_bar() #147

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
None as default
hagenw committed Jul 1, 2024
commit ff1906122b0697e6ccf769a2ebd974f3cd377708
30 changes: 26 additions & 4 deletions audeer/core/tqdm.py
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ def progress_bar(
total: int = None,
desc: str = None,
disable: bool = False,
maximum_refresh_time: typing.Optional = 1,
maximum_refresh_time: float = None,
) -> tqdm:
r"""Progress bar with optional text on the right.

@@ -107,10 +107,32 @@ def progress_bar(
)


def tqdm_wrapper(iterable, maximum_refresh_time, *args, **kwargs):
r"""Progress bar wrapper to enforce update once a second.
def tqdm_wrapper(
iterable: typing.Sequence,
maximum_refresh_time: float,
*args,
**kwargs,
) -> tqdm:
r"""Tqdm progress bar wrapper to enforce update once a second.

When using tqdm with large time durations
between single steps of the iteration,
it will not automatically update the elapsed time,
but needs to be forced,
see https://github.com/tqdm/tqdm/issues/861#issuecomment-2197893883.

Args:
iterable: sequence to iterate through
maximum_refresh_time: refresh the progress bar
at least every ``maximum_refresh_time`` seconds,
using another thread.
If ``None``,
no refreshing is enforced
args: arguments passed on to ``tqdm``
kwargs: keyword arguments passed on to ``tqdm``

See https://github.com/tqdm/tqdm/issues/861#issuecomment-2197893883.
Returns:
progress bar object

"""
pbar = tqdm(iterable, *args, **kwargs)