hgext/progress.py
changeset 23908 5502bd79d052
parent 23907 63c7783a5928
child 25186 80c5b2666a96
equal deleted inserted replaced
23907:63c7783a5928 23908:5502bd79d052
    35 characters.
    35 characters.
    36 """
    36 """
    37 
    37 
    38 import sys
    38 import sys
    39 import time
    39 import time
       
    40 import threading
    40 
    41 
    41 from mercurial.i18n import _
    42 from mercurial.i18n import _
    42 testedwith = 'internal'
    43 testedwith = 'internal'
    43 
    44 
    44 from mercurial import encoding
    45 from mercurial import encoding
    88     return _("%dy%02dw") % (years, weeks)
    89     return _("%dy%02dw") % (years, weeks)
    89 
    90 
    90 class progbar(object):
    91 class progbar(object):
    91     def __init__(self, ui):
    92     def __init__(self, ui):
    92         self.ui = ui
    93         self.ui = ui
       
    94         self._refreshlock = threading.Lock()
    93         self.resetstate()
    95         self.resetstate()
    94 
    96 
    95     def resetstate(self):
    97     def resetstate(self):
    96         self.topics = []
    98         self.topics = []
    97         self.topicstates = {}
    99         self.topicstates = {}
   239         else:
   241         else:
   240             return False
   242             return False
   241 
   243 
   242     def progress(self, topic, pos, item='', unit='', total=None):
   244     def progress(self, topic, pos, item='', unit='', total=None):
   243         now = time.time()
   245         now = time.time()
       
   246         self._refreshlock.acquire()
   244         try:
   247         try:
   245             if pos is None:
   248             if pos is None:
   246                 self.starttimes.pop(topic, None)
   249                 self.starttimes.pop(topic, None)
   247                 self.startvals.pop(topic, None)
   250                 self.startvals.pop(topic, None)
   248                 self.topicstates.pop(topic, None)
   251                 self.topicstates.pop(topic, None)
   271                 if now - self.lastprint >= self.refresh and self.topics:
   274                 if now - self.lastprint >= self.refresh and self.topics:
   272                     if self._oktoprint(now):
   275                     if self._oktoprint(now):
   273                         self.lastprint = now
   276                         self.lastprint = now
   274                         self.show(now, topic, *self.topicstates[topic])
   277                         self.show(now, topic, *self.topicstates[topic])
   275         finally:
   278         finally:
   276             pass
   279             self._refreshlock.release()
   277 
   280 
   278 _singleton = None
   281 _singleton = None
   279 
   282 
   280 def uisetup(ui):
   283 def uisetup(ui):
   281     global _singleton
   284     global _singleton