Skip to content

Commit

Permalink
BUG: Make sure that raised exceptions abort queued cells
Browse files Browse the repository at this point in the history
  • Loading branch information
bnmajor committed Dec 19, 2023
1 parent 9aba3d9 commit c18114d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions itkwidgets/cell_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c18114d

Please sign in to comment.