[core] fix Graph.stopExecution

iterate over and terminate running chunks
This commit is contained in:
Yann Lanthony 2017-11-08 18:12:03 +01:00
parent e472d0e1fa
commit 9860828c67
2 changed files with 27 additions and 15 deletions

View file

@ -584,6 +584,9 @@ class NodeChunk(BaseObject):
self.upgradeStatusTo(Status.SUCCESS)
def stopProcess(self):
self.node.nodeDesc.stopProcess(self)
statusChanged = Signal()
statusName = Property(str, statusName.fget, notify=statusChanged)
statisticsChanged = Signal()
@ -823,9 +826,6 @@ class Node(BaseObject):
def beginSequence(self):
self.upgradeStatusTo(Status.SUBMITTED_LOCAL)
def stopProcess(self):
self.nodeDesc.stop(self)
def processIteration(self, iteration):
self.chunks[iteration].process()
@ -972,7 +972,6 @@ class Graph(BaseObject):
node._name = uniqueName
node.graph = self
self._nodes.add(node)
self.stopExecutionRequested.connect(node.stopProcess)
def addNode(self, node, uniqueName=None):
"""
@ -1322,8 +1321,9 @@ class Graph(BaseObject):
self.updateStatusFromCache()
def stopExecution(self):
""" Request graph execution to be stopped """
self.stopExecutionRequested.emit()
""" Request graph execution to be stopped by terminating running chunks"""
for chunk in self.iterChunksByStatus(Status.RUNNING):
chunk.stopProcess()
def clearSubmittedNodes(self):
""" Reset the status of already submitted nodes to Status.NONE """
@ -1331,6 +1331,20 @@ class Graph(BaseObject):
for chunk in node.alreadySubmittedChunks():
chunk.upgradeStatusTo(Status.NONE)
def iterChunksByStatus(self, status):
""" Iterate over NodeChunks with the given status """
for node in self.nodes:
for chunk in node.chunks:
if chunk.status.status == status:
yield chunk
def getChunksByStatus(self, status):
""" Return the list of NodeChunks with the given status """
chunks = []
for node in self.nodes:
chunks += [chunk for chunk in node.chunks if chunk.status.status == status]
return chunks
@property
def nodes(self):
return self._nodes
@ -1355,8 +1369,6 @@ class Graph(BaseObject):
cacheDirChanged = Signal()
cacheDir = Property(str, cacheDir.fget, cacheDir.fset, notify=cacheDirChanged)
stopExecutionRequested = Signal()
def loadGraph(filepath):
"""