-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[Data] Improve Progress Bar Display in Non-Interactive Terminals #58913
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
Open
daiping8
wants to merge
8
commits into
ray-project:master
Choose a base branch
from
daiping8:dat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−48
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
13032f6
feat(progress-bar): Improve Progress Bar Display in Non-Interactive T…
daiping8 a2f6e10
fix(progress-bar): Fix the problem of incorrectly enabling the progre…
daiping8 2e6c0d1
Update python/ray/data/_internal/progress_bar.py
daiping8 f616fcb
Update python/ray/data/tests/test_progress_bar.py
daiping8 ae8086e
Update python/ray/data/tests/test_progress_bar.py
daiping8 2685581
Update python/ray/data/tests/test_progress_bar.py
daiping8 a903241
style(python/ray/data/_internal/progress_bar.py)
daiping8 cec72cf
Merge branch 'dat' of https://github.com/daiping8/ray into dat
daiping8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import logging | ||
| import sys | ||
| import threading | ||
| import time | ||
| from abc import ABC, abstractmethod | ||
| from typing import Any, List, Optional | ||
|
|
||
|
|
@@ -131,14 +133,26 @@ def __init__( | |
| ): | ||
| self._desc = truncate_operator_name(name, self.MAX_NAME_LENGTH) | ||
| self._progress = 0 | ||
| self._total = total | ||
| # Prepend a space to the unit for better formatting. | ||
| if unit[0] != " ": | ||
| unit = " " + unit | ||
|
|
||
| if enabled is None: | ||
| if not sys.stdout.isatty(): | ||
| enabled = False | ||
| if log_once("progress_bar_disabled"): | ||
| logger.info( | ||
| "Progress bar disabled because stdout is a non-interactive terminal." | ||
| ) | ||
| elif enabled is None: | ||
| # When enabled is None (not explicitly set by the user), | ||
| # check DataContext setting | ||
| from ray.data.context import DataContext | ||
|
|
||
| enabled = DataContext.get_current().enable_progress_bars | ||
|
|
||
| self._use_logging = not sys.stdout.isatty() | ||
|
|
||
| if not enabled: | ||
| self._bar = None | ||
| elif tqdm: | ||
|
|
@@ -163,6 +177,13 @@ def __init__( | |
| needs_warning = False | ||
| self._bar = None | ||
|
|
||
| # For logging progress in non-interactive terminals | ||
| self._last_logged_time = 0 | ||
| # Log interval in seconds | ||
| from ray.data.context import DataContext | ||
|
|
||
| self._log_interval = DataContext.get_current().progress_bar_log_interval | ||
|
|
||
| def set_description(self, name: str) -> None: | ||
| name = truncate_operator_name(name, self.MAX_NAME_LENGTH) | ||
| if self._bar and name != self._desc: | ||
|
|
@@ -185,6 +206,23 @@ def update(self, increment: int = 0, total: Optional[int] = None) -> None: | |
| # If the progress goes over 100%, update the total. | ||
| self._bar.total = self._progress | ||
| self._bar.update(increment) | ||
| elif self._use_logging and (increment != 0): | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self._progress += increment | ||
| if total is not None: | ||
| self._total = total | ||
|
|
||
| # Log progress periodically | ||
| current_time = time.time() | ||
| time_diff = current_time - self._last_logged_time | ||
| should_log = (self._last_logged_time == 0) or ( | ||
| time_diff >= self._log_interval | ||
| ) | ||
|
|
||
| if should_log: | ||
| logger.info( | ||
| f"Progress ({self._desc}): {self._progress}/{self._total or 'unknown'}" | ||
| ) | ||
| self._last_logged_time = current_time | ||
daiping8 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+209
to
+225
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should probably also into |
||
|
|
||
| def close(self): | ||
| if self._bar: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.