progress: remove lock draft
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 01 Apr 2017 18:49:02 -0700
changeset 36864 50727862d0e1a0e1dcb058754880af34e256b040
parent 36760 6be6e4becaafd1bf24f01a2d0464df9cea67588d
child 36865 57ae50b488bebcbf9560494ecd18ba503aeeef2e
push id491
push usergszorc@mozilla.com
push dateThu, 06 Apr 2017 06:04:00 +0000
progress: remove lock A threading.Lock() was added in 5502bd79d052 "to prepare for introducing a thread." However, I can't figure out what thread this refers to. This changeset was never sent to the mailing list and AFAICT there was no public discussion about it. I suspect it has to do with some Facebook experiment that never panned out. Since locks have a cost to them and since I'm about to refactor this code, let's remove the lock.
mercurial/progress.py
--- a/mercurial/progress.py
+++ b/mercurial/progress.py
@@ -2,17 +2,16 @@
 #
 # Copyright (C) 2010 Augie Fackler <durin42@gmail.com>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from __future__ import absolute_import
 
-import threading
 import time
 
 from .i18n import _
 from . import encoding
 
 def spacejoin(*args):
     return ' '.join(s for s in args if s)
 
@@ -58,17 +57,16 @@ def fmtremaining(seconds):
     years = weeks // 52
     weeks -= years * 52
     # i18n: format X years and YY weeks as "XyYYw"
     return _("%dy%02dw") % (years, weeks)
 
 class progbar(object):
     def __init__(self, ui):
         self.ui = ui
-        self._refreshlock = threading.Lock()
         self.resetstate()
 
     def resetstate(self):
         self.topics = []
         self.topicstates = {}
         self.starttimes = {}
         self.startvals = {}
         self.printed = False
@@ -214,42 +212,38 @@ class progbar(object):
             # it's been long enough we should print anyway
             or now - self.lastprint >= self.changedelay):
             return True
         else:
             return False
 
     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)
-                self.startvals.pop(topic, None)
-                self.topicstates.pop(topic, None)
-                # reset the progress bar if this is the outermost topic
-                if self.topics and self.topics[0] == topic and self.printed:
-                    self.complete()
-                    self.resetstate()
-                # truncate the list of topics assuming all topics within
-                # this one are also closed
-                if topic in self.topics:
-                    self.topics = self.topics[:self.topics.index(topic)]
-                    # reset the last topic to the one we just unwound to,
-                    # so that higher-level topics will be stickier than
-                    # lower-level topics
-                    if self.topics:
-                        self.lasttopic = self.topics[-1]
-                    else:
-                        self.lasttopic = None
-            else:
-                if topic not in self.topics:
-                    self.starttimes[topic] = now
-                    self.startvals[topic] = pos
-                    self.topics.append(topic)
-                self.topicstates[topic] = pos, item, unit, total
-                self.curtopic = topic
-                if now - self.lastprint >= self.refresh and self.topics:
-                    if self._oktoprint(now):
-                        self.lastprint = now
-                        self.show(now, topic, *self.topicstates[topic])
-        finally:
-            self._refreshlock.release()
+        if pos is None:
+            self.starttimes.pop(topic, None)
+            self.startvals.pop(topic, None)
+            self.topicstates.pop(topic, None)
+            # reset the progress bar if this is the outermost topic
+            if self.topics and self.topics[0] == topic and self.printed:
+                self.complete()
+                self.resetstate()
+            # truncate the list of topics assuming all topics within
+            # this one are also closed
+            if topic in self.topics:
+                self.topics = self.topics[:self.topics.index(topic)]
+                # reset the last topic to the one we just unwound to,
+                # so that higher-level topics will be stickier than
+                # lower-level topics
+                if self.topics:
+                    self.lasttopic = self.topics[-1]
+                else:
+                    self.lasttopic = None
+        else:
+            if topic not in self.topics:
+                self.starttimes[topic] = now
+                self.startvals[topic] = pos
+                self.topics.append(topic)
+            self.topicstates[topic] = pos, item, unit, total
+            self.curtopic = topic
+            if now - self.lastprint >= self.refresh and self.topics:
+                if self._oktoprint(now):
+                    self.lastprint = now
+                    self.show(now, topic, *self.topicstates[topic])