Skip to content

Commit

Permalink
BUG: Wait for unnamed viewers before creating the next
Browse files Browse the repository at this point in the history
  • Loading branch information
bnmajor committed Dec 8, 2023
1 parent c509c4d commit 5efe59f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions itkwidgets/cell_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def data(self):
def not_created(self):
# Return a list of names of viewers that have not been created yet
names = []
for vals in self.data.values():
if vals['name'] is not None and not vals['status']:
names.append(vals['name'])
for key, val in self.data.items():
name = val['name']
if not val['status']:
name = name if name is not None else key
names.append(name)
return names

@property
Expand Down Expand Up @@ -122,7 +124,7 @@ def create_task(self, fn):

def capture_event(self, stream, ident, parent):
self._events.put((stream, ident, parent))
if self._events.qsize() == 1 and self.ready_to_run_next_cell(parent):
if self._events.qsize() == 1 and self.ready_to_run_next_cell():
# We've added a new task to an empty queue.
# Begin executing tasks again.
self.create_task(self.execute_next_request)
Expand All @@ -137,12 +139,10 @@ def all_getters_resolved(self):
getters_resolved = [f.done() for f in self.results.values()]
return all(getters_resolved)

def ready_to_run_next_cell(self, parent):
def ready_to_run_next_cell(self):
# Any itk_viewer objects need to be available and all getters/setters
# need to be resolved
raw = parent.get("content", {}).get("code", "")
viewers_not_ready = [n for n in self.viewers.not_created if n in raw]
self.waiting_on_viewer = any(viewers_not_ready)
self.waiting_on_viewer = len(self.viewers.not_created)
return self.all_getters_resolved and not self.waiting_on_viewer

async def execute_next_request(self):
Expand All @@ -155,7 +155,7 @@ async def execute_next_request(self):
# Fetch the next request if we haven't already
self.current_request = self._events.get()

if self.ready_to_run_next_cell(self.current_request[2]):
if self.ready_to_run_next_cell():
# Continue processing the remaining queued tasks
await self._execute_next_request()

Expand Down

0 comments on commit 5efe59f

Please sign in to comment.