progress: add a lock to prepare for introducing a thread
authorSolomon Matthews <smat@fb.com>
Sat, 17 Jan 2015 13:13:16 -0800
changeset 23908 5502bd79d052
parent 23907 63c7783a5928
child 23909 0760f023a34b
progress: add a lock to prepare for introducing a thread
hgext/progress.py
--- a/hgext/progress.py	Sat Jan 17 13:10:37 2015 -0800
+++ b/hgext/progress.py	Sat Jan 17 13:13:16 2015 -0800
@@ -37,6 +37,7 @@
 
 import sys
 import time
+import threading
 
 from mercurial.i18n import _
 testedwith = 'internal'
@@ -90,6 +91,7 @@
 class progbar(object):
     def __init__(self, ui):
         self.ui = ui
+        self._refreshlock = threading.Lock()
         self.resetstate()
 
     def resetstate(self):
@@ -241,6 +243,7 @@
 
     def progress(self, topic, pos, item='', unit='', total=None):
         now = time.time()
+        self._refreshlock.acquire()
         try:
             if pos is None:
                 self.starttimes.pop(topic, None)
@@ -273,7 +276,7 @@
                         self.lastprint = now
                         self.show(now, topic, *self.topicstates[topic])
         finally:
-            pass
+            self._refreshlock.release()
 
 _singleton = None