]> arthur.barton.de Git - bup.git/commitdiff
qprogress(): Check if stderr is connected to a terminal
authorAlexander Barton <alex@barton.de>
Sun, 28 Dec 2014 19:31:23 +0000 (20:31 +0100)
committerAlexander Barton <alex@barton.de>
Wed, 31 Dec 2014 17:48:11 +0000 (18:48 +0100)
This minimize overhead of the time() function when stderr is not
connected to a terminal.

Signed-off-by: Alexander Barton <alex@barton.de>
lib/bup/helpers.py

index ceab7ecc24942d14442d12756b406e8971c664d2..7a153203db6c3e7bf73eb1e910f5af04ce4ebc59 100644 (file)
@@ -91,12 +91,14 @@ def qprogress(s):
     """Calls progress() only if we haven't printed progress in a while.
 
     This avoids overloading the stderr buffer with excess junk.
+    We do the TTY check here, too, to minimize overhead of the time() function.
     """
     global _last_prog
-    now = time.time()
-    if now - _last_prog > 0.1:
-        progress(s)
-        _last_prog = now
+    if istty2:
+        now = time.time()
+        if now - _last_prog > 0.1:
+            progress(s)
+            _last_prog = now
 
 
 def mkdirp(d, mode=None):