comparison mercurial/progress.py @ 38423:6bd9f18d31a8

progress: use context manager for lock Differential Revision: https://phab.mercurial-scm.org/D3820
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 19 Jun 2018 22:06:28 -0700
parents 2831d918e1b4
children b34d0a6ef936
comparison
equal deleted inserted replaced
38422:35b50237908b 38423:6bd9f18d31a8
263 self.startvals[topic] = pos - newdelta 263 self.startvals[topic] = pos - newdelta
264 self.starttimes[topic] = now - interval 264 self.starttimes[topic] = now - interval
265 265
266 def progress(self, topic, pos, item='', unit='', total=None): 266 def progress(self, topic, pos, item='', unit='', total=None):
267 now = time.time() 267 now = time.time()
268 self._refreshlock.acquire() 268 with self._refreshlock:
269 try:
270 if pos is None: 269 if pos is None:
271 self.starttimes.pop(topic, None) 270 self.starttimes.pop(topic, None)
272 self.startvals.pop(topic, None) 271 self.startvals.pop(topic, None)
273 self.topicstates.pop(topic, None) 272 self.topicstates.pop(topic, None)
274 # reset the progress bar if this is the outermost topic 273 # reset the progress bar if this is the outermost topic
296 self._calibrateestimate(topic, now, pos) 295 self._calibrateestimate(topic, now, pos)
297 if now - self.lastprint >= self.refresh and self.topics: 296 if now - self.lastprint >= self.refresh and self.topics:
298 if self._oktoprint(now): 297 if self._oktoprint(now):
299 self.lastprint = now 298 self.lastprint = now
300 self.show(now, topic, *self.topicstates[topic]) 299 self.show(now, topic, *self.topicstates[topic])
301 finally:
302 self._refreshlock.release()