Skip to content

Commit

Permalink
Fixing a bug that'd make a LoadingBar be stuck when used as a context…
Browse files Browse the repository at this point in the history
… manager if the inside-context-manager code finishes too quickly. Also, updating Refresher a little bit.
  • Loading branch information
CRImier committed Feb 13, 2019
1 parent 53435bf commit 014fcc7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ui/loading_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def set_message(self, new_message):
self.refresh()

def run_in_background(self):
if self.t is not None or self.in_foreground:
if self.t is not None or self.is_active:
raise Exception("BaseLoadingIndicator already running!")
self.t = Thread(target=self.activate, name="Background thread for LoadingIndicator {}".format(self.name))
self.t.daemon = True
Expand All @@ -67,6 +67,7 @@ def stop(self):

def __enter__(self):
self.run_in_background()
self.wait_for_active()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
Expand Down Expand Up @@ -104,10 +105,9 @@ def __init__(self, i, o, *args, **kwargs):
self.message = kwargs.pop("message", None)
BaseLoadingIndicator.__init__(self, i, o, refresh_interval=0.01, *args, **kwargs)

def activate(self):
def before_activate(self):
self.start_time = time()
self.counter.start()
return Refresher.activate(self)

@to_be_foreground
def refresh(self):
Expand Down

0 comments on commit 014fcc7

Please sign in to comment.