Skip to content

Commit

Permalink
Merge pull request #721 from bnmajor/flush-exceptions
Browse files Browse the repository at this point in the history
BUG: Make sure that raised exceptions abort queued cells
  • Loading branch information
thewtex authored Dec 19, 2023
2 parents 2f267e2 + c18114d commit b38d549
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 b38d549

Please sign in to comment.