diff --git a/meshroom/core/graph.py b/meshroom/core/graph.py index 8ad39a0f..4967de39 100644 --- a/meshroom/core/graph.py +++ b/meshroom/core/graph.py @@ -446,10 +446,10 @@ class Node(BaseObject): self.upgradeStatusTo(Status.ERROR) raise finally: - statThread.running = False - # Don't need to join, the thread will finish a bit later. - # statThread.join() self._subprocess = None + # ask and wait for the stats thread to terminate + statThread.stopRequest() + statThread.join() self.upgradeStatusTo(Status.SUCCESS) diff --git a/meshroom/core/stats.py b/meshroom/core/stats.py index 7e18a8c7..8de0a4bd 100644 --- a/meshroom/core/stats.py +++ b/meshroom/core/stats.py @@ -191,8 +191,8 @@ class StatisticsThread(threading.Thread): threading.Thread.__init__(self) self.node = node self.proc = None - self.running = True self.statistics = self.node.statistics + self._stopFlag = threading.Event() def updateStats(self): self.lastTime = time.time() @@ -200,7 +200,14 @@ class StatisticsThread(threading.Thread): self.node.saveStatistics() def run(self): - while self.running: + while True: self.updateStats() - time.sleep(60) + if self._stopFlag.wait(60): + # stopFlag has been set + # update stats one last time and exit main loop + self.updateStats() + return + def stopRequest(self): + """ Request the thread to exit as soon as possible. """ + self._stopFlag.set()