Skip to content

Conversation

@daiping8
Copy link
Contributor

Description

I followed the guidance in #57734 to use logging instead of progress bars for non-interactive terminals.

Option 1: Auto-detect non-interactive terminals and disable progress bars entirely
Option 3: Use a simpler logging-based approach for non-interactive terminals (e.g., "Completed 50/100 tasks")

Specifically:

  • Disable progress bar display in non-interactive terminals
  • Implement progress output in the form of logs in non-interactive terminals
  • Add configuration for the interval time of progress log output
  • Optimize the update logic of the progress bar to support cases with unknown total counts
  • Related test cases

Verification

This can be verified by the following test case.

import ray
import time
import numpy as np

def create_test_data():
    data = []
    for i in range(1000):
        data.append({
            "id": i,
            "value": np.random.rand(),
            "category": f"category_{i % 10}"
        })
    return data

def slow_processing_function(batch):
    time.sleep(0.01)
    batch["processed_value"] = batch["value"] * 2
    batch["is_even"] = batch["id"] % 2 == 0
    return batch

def main():
    ray.init(num_cpus=4)
    
    from ray.data.context import DataContext
    ctx = DataContext.get_current()
    ctx.enable_progress_bars = False
    
    try:
        test_data = create_test_data()
        ds = ray.data.from_items(test_data)
        processed_ds = ds.map(slow_processing_function)
        filtered_ds = processed_ds.filter(lambda x: x["id"] % 5 == 0)
        grouped_result = filtered_ds.groupby("category").count()      
        result = grouped_result.take_all()      
        # Show first 5 results
        for item in result[:5]:
            print(f"  {item}")    
        print(processed_ds.stats())        
    finally:
        ray.shutdown()


if __name__ == "__main__":
    main()

In the interactive terminal:
image

In the non-interactive terminal:
image

Related issues

Closes #57734

…erminals

- Disable progress bar display in non-interactive terminals
- Implement progress output in the form of logs in non-interactive terminals
- Add configuration for the interval time of progress log output
- Optimize the update logic of the progress bar to support cases with unknown total counts

Change-Id: I96704bbeb04460bc1c10c6fb3a798eccf8a7169a
Signed-off-by: daiping8 <[email protected]>
…ss bar in non-interactive terminals

- Modified the initialization logic of the ProgressBar class to ensure that the progress bar is disabled in non-interactive terminals
- Updated the test case to verify that the progress bar is correctly disabled in non-interactive terminals

Change-Id: If5fabca38ed85170cac3d02671f86ea7bef5a5a6
Signed-off-by: daiping8 <[email protected]>
@daiping8 daiping8 requested a review from a team as a code owner November 22, 2025 06:13
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively improves the progress bar display for non-interactive terminals by switching to a logging-based approach. The changes are well-structured, covering the core logic, configuration, and corresponding tests. My review includes a few suggestions to enhance code clarity and maintainability by simplifying logical conditions and reducing code duplication in the tests.

daiping8 and others added 4 commits November 22, 2025 14:18
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Ping Dai <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Ping Dai <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Ping Dai <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Ping Dai <[email protected]>
Change-Id: Ifc860815e025ad126f03b24faffba7935d334c06
Signed-off-by: daiping8 <[email protected]>
Change-Id: I051ca775f921dadb4c734fd8368f77fd62328db8
Signed-off-by: daiping8 <[email protected]>
@ray-gardener ray-gardener bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Prevent progress bars from spamming non-interactive terminals

1 participant