From e1c595c7e5bd00fc7900471ea13f6de2fa8d165d Mon Sep 17 00:00:00 2001 From: ptmcg Date: Sun, 6 Feb 2022 13:53:06 -0600 Subject: [PATCH] task._progress change default_factory to create deque(maxlen=1000), to avoid run-time while loop to trim to length 1000 --- rich/progress.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rich/progress.py b/rich/progress.py index fe35b6c17..115ae8160 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -475,7 +475,7 @@ class Task: """Optional[float]: The last speed for a finished task.""" _progress: Deque[ProgressSample] = field( - default_factory=deque, init=False, repr=False + default_factory=lambda: deque(maxlen=1000), init=False, repr=False ) _lock: RLock = field(repr=False, default_factory=RLock) @@ -813,8 +813,6 @@ def update( popleft = _progress.popleft while _progress and _progress[0].timestamp < old_sample_time: popleft() - while len(_progress) > 1000: - popleft() if update_completed > 0: _progress.append(ProgressSample(current_time, update_completed)) if task.completed >= task.total and task.finished_time is None: