From 13d0bd8b466231dace8a2eff910c2711df72f785 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 28 Mar 2018 15:06:05 -0700 Subject: [PATCH] Limit progress updates to avoid swamping the TTY This makes the values more readable for large downloads on fast connections. 200 ms value chosen from wget. --- news/5124.trivial | 1 + src/pip/_internal/utils/ui.py | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 news/5124.trivial diff --git a/news/5124.trivial b/news/5124.trivial new file mode 100644 index 000000000..bc0a19b87 --- /dev/null +++ b/news/5124.trivial @@ -0,0 +1 @@ +Limit progress bar update interval to 200 ms. diff --git a/src/pip/_internal/utils/ui.py b/src/pip/_internal/utils/ui.py index 8ade1e210..52302ac98 100644 --- a/src/pip/_internal/utils/ui.py +++ b/src/pip/_internal/utils/ui.py @@ -137,6 +137,7 @@ class DownloadProgressMixin(object): def __init__(self, *args, **kwargs): super(DownloadProgressMixin, self).__init__(*args, **kwargs) self.message = (" " * (get_indentation() + 2)) + self.message + self.last_update = 0.0 @property def downloaded(self): @@ -161,6 +162,15 @@ class DownloadProgressMixin(object): self.next(n) self.finish() + def update(self): + # limit updates to avoid swamping the TTY + now = time.time() + if now < self.last_update + 0.2: + return + self.last_update = now + + super(DownloadProgressMixin, self).update() + class WindowsMixin(object):