From b8741fb6da2b1ae72a9ef39f68d46ffe4515a8d0 Mon Sep 17 00:00:00 2001 From: Fabien Roger Date: Fri, 18 Feb 2022 00:44:39 +0100 Subject: [PATCH] :beetle: Prevent crash when there is a loop --- pyflow/blocks/executableblock.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyflow/blocks/executableblock.py b/pyflow/blocks/executableblock.py index 46ef692e..de92d448 100644 --- a/pyflow/blocks/executableblock.py +++ b/pyflow/blocks/executableblock.py @@ -156,9 +156,18 @@ def custom_bfs(self, start_node, reverse=False): to_transmit: List[List[Union["ExecutableBlock", "Edge"]]] = [[start_node]] to_visit: List["ExecutableBlock"] = [start_node] + + # Set to make sure to never execute the same block twice + visited: Set["ExecutableBlock"] = set([]) + while to_visit: # Remove duplicates - to_visit = list(set(to_visit)) + to_visit_set = set(to_visit) + to_visit_set.difference_update(visited) + to_visit = list(to_visit_set) + + # Update the visited block set + visited.update(to_visit_set) # Gather connected edges edges_to_visit = []