Skip to content

Commit

Permalink
synchronize shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jun 6, 2024
1 parent 6ca232e commit 7cfa1a6
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2752,23 +2752,24 @@ def is_mounted(self, widget: Widget) -> bool:
async def _close_all(self) -> None:
"""Close all message pumps."""

# Close all screens on all stacks:
for stack in self._screen_stacks.values():
for stack_screen in reversed(stack):
if stack_screen._running:
await self._prune_node(stack_screen)
stack.clear()

# Close pre-defined screens.
for screen in self.SCREENS.values():
if isinstance(screen, Screen) and screen._running:
await self._prune_node(screen)

# Close any remaining nodes
# Should be empty by now
remaining_nodes = list(self._registry)
for child in remaining_nodes:
await child._close_messages()
async with self._dom_lock:
# Close all screens on all stacks:
for stack in self._screen_stacks.values():
for stack_screen in reversed(stack):
if stack_screen._running:
await self._prune_node(stack_screen)
stack.clear()

# Close pre-defined screens.
for screen in self.SCREENS.values():
if isinstance(screen, Screen) and screen._running:
await self._prune_node(screen)

# Close any remaining nodes
# Should be empty by now
remaining_nodes = list(self._registry)
for child in remaining_nodes:
await child._close_messages()

async def _shutdown(self) -> None:
self._begin_batch() # Prevents any layout / repaint while shutting down
Expand Down Expand Up @@ -3342,7 +3343,10 @@ async def prune_widgets_task(
await self._prune_nodes(widgets)
finally:
finished_event.set()
self._update_mouse_over(self.screen)
try:
self._update_mouse_over(self.screen)
except ScreenStackError:
pass
if parent is not None:
parent.refresh(layout=True)

Expand Down

0 comments on commit 7cfa1a6

Please sign in to comment.