From ac07006ae72dabf3664b49f0afe4ca9e72a1bc10 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sun, 14 Aug 2022 11:04:53 +0200 Subject: [PATCH] Limit number of prints per second --- twitchdl/progress.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/twitchdl/progress.py b/twitchdl/progress.py index d34d09b..a14ec64 100644 --- a/twitchdl/progress.py +++ b/twitchdl/progress.py @@ -29,6 +29,7 @@ class Progress: vod_count: int downloaded: int = 0 estimated_total: Optional[int] = None + last_printed: float = field(default_factory=time.time) progress_bytes: int = 0 progress_perc: int = 0 remaining_time: Optional[int] = None @@ -107,6 +108,12 @@ class Progress: self.remaining_time = int((self.estimated_total - self.progress_bytes) / self.speed) if self.estimated_total and self.speed else None def print(self): + now = time.time() + + # Don't print more often than 10 times per second + if now - self.last_printed < 0.1: + return + progress = " ".join([ f"Downloaded {self.vod_downloaded_count}/{self.vod_count} VODs", f"({self.progress_perc}%)", @@ -117,3 +124,4 @@ class Progress: ]) print_out(f"\r{progress} ", end="") + self.last_printed = now