From c18114d9e1da8a3a4f40840cc658c7aa22b38031 Mon Sep 17 00:00:00 2001 From: Brianna Major Date: Tue, 19 Dec 2023 17:10:15 -0500 Subject: [PATCH] BUG: Make sure that raised exceptions abort queued cells --- itkwidgets/cell_watcher.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/itkwidgets/cell_watcher.py b/itkwidgets/cell_watcher.py index 57d7d5f6..747b53aa 100644 --- a/itkwidgets/cell_watcher.py +++ b/itkwidgets/cell_watcher.py @@ -294,16 +294,19 @@ def update_namespace(self) -> None: """Update the namespace variables with the results from the getters""" # FIXME: This is a temporary "fix" and does not handle updating output keys = [k for k in self.shell.user_ns.keys()] - for key in keys: - value = self.shell.user_ns[key] - if asyncio.isfuture(value) and ( - isinstance(value, FuturePromise) or isinstance(value, asyncio.Task) - ): - # Functions that need to return values from asynchronous - # network requests return futures. They should all be resolved - # now, so use the result. - self.shell.user_ns[key] = value.result() - self.results.clear() + try: + for key in keys: + value = self.shell.user_ns[key] + if asyncio.isfuture(value) and (isinstance(value, FuturePromise) or isinstance(value, asyncio.Task)): + # Getters/setters return futures + # They should all be resolved now, so use the result + self.shell.user_ns[key] = value.result() + self.results.clear() + except Exception as e: + self.results.clear() + self.abort_all = True + self.create_task(self._execute_next_request) + raise e def _callback(self, *args, **kwargs) -> None: """After each future resolves check to see if they are all resolved. If