Skip to content

Commit

Permalink
Add the context manager flushing()
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed May 19, 2024
1 parent e390719 commit 265a5b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion atpbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"find_reporter",
"register_reporter",
"flush",
"flushing",
"disable",
"__version__",
]
from .__about__ import __version__
from .funcs import disable, find_reporter, flush, register_reporter
from .funcs import disable, find_reporter, flush, flushing, register_reporter
from .main import atpbar
9 changes: 9 additions & 0 deletions atpbar/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ def flush() -> None:
_machine.flush()


@contextlib.contextmanager
def flushing() -> Iterator[None]:
'''Flushes progress bars on exit'''
try:
yield

Check warning on line 67 in atpbar/funcs.py

View check run for this annotation

Codecov / codecov/patch

atpbar/funcs.py#L66-L67

Added lines #L66 - L67 were not covered by tests
finally:
flush()

Check warning on line 69 in atpbar/funcs.py

View check run for this annotation

Codecov / codecov/patch

atpbar/funcs.py#L69

Added line #L69 was not covered by tests


def disable() -> None:
"""disables progress bars
Expand Down

0 comments on commit 265a5b7

Please sign in to comment.