rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Elapsed time stuck when restarted after stop_task()

Open Lucide opened this issue 1 year ago • 3 comments

  • [x] I've checked docs and closed issues for possible solutions.
  • [x] I can't find my issue in the FAQ.

Describe the bug Awesome tool

elapsed-based components do not recover when being restarted after a task_stop() call. A quick skim of the classes did not reveal immediately the issue, but I am a bit inexperienced in python specifically.

import time
from rich.console import Group
from rich.live import Live
from rich.progress import (
    BarColumn,
    Progress,
    TextColumn,
    TimeElapsedColumn,
)

progress = Progress(TimeElapsedColumn(), BarColumn(), TextColumn("{task.description}"))
task_id = progress.add_task("stop_task() doesn't recover", total=90)

with Live(progress):
    for _ in range(30):
        time.sleep(0.1)
        progress.advance(task_id, 1)

    progress.stop_task(task_id)
    progress.update(task_id, description="task stopped")

    for _ in range(30):
        time.sleep(0.1)
        progress.advance(task_id, 1)

    progress.reset(task_id, completed=60) # start: bool = True
    # progress.start_task(task_id)
    progress.update(task_id, description="task restarted")

    for _ in range(30):
        time.sleep(0.1)
        progress.advance(task_id, 1)

Platform

Windows, windows terminal, probably not terminal related
python -m rich.diagnose
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=122 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 59                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=122, height=59),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=122,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=59,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=122, height=59)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 122                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭── <class 'rich._windows.WindowsConsoleFeatures'> ───╮
│ Windows features available.                         │
│                                                     │
│ ╭─────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │
│ ╰─────────────────────────────────────────────────╯ │
│                                                     │
│ truecolor = True                                    │
│        vt = True                                    │
╰─────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'CLICOLOR': None,              │
│     'COLORTERM': 'truecolor',      │
│     'COLUMNS': None,               │
│     'JPY_PARENT_PID': None,        │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'LINES': None,                 │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': 'vscode',      │
│     'TERM': None,                  │
│     'TTY_COMPATIBLE': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Windows"
pip freeze | grep rich
rich           14.0.0

Lucide avatar Apr 19 '25 14:04 Lucide

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Apr 19 '25 14:04 github-actions[bot]

Hmm it's just seems that reset() doesn't set stop_time to None, only finished_time...

@property
def elapsed(self) -> Optional[float]:
    """Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started."""
    if self.start_time is None:
        return None
    if self.stop_time is not None:
        return self.stop_time - self.start_time
    return self.get_time() - self.start_time

Bah, the way it is written, this almost seems intended behaviour.. But on the other hand, Progress offers no api to clear stop_time and self._tasks: Dict[TaskID, Task] is marked private 🤔

Lucide avatar Apr 19 '25 18:04 Lucide

test comment - will be deleted

Krishnachaitanyakc avatar Mar 25 '26 02:03 Krishnachaitanyakc