From 3c7391408616c466424249547d812c032cc3574b Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 13 Nov 2022 13:22:56 +0000 Subject: [PATCH] fix deadlock on tests --- src/textual/_animator.py | 9 ++++++--- src/textual/app.py | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/textual/_animator.py b/src/textual/_animator.py index 8270456ac..25c7e6db8 100644 --- a/src/textual/_animator.py +++ b/src/textual/_animator.py @@ -189,9 +189,12 @@ class Animator: async def stop(self) -> None: """Stop the animator task.""" try: - await self._timer.stop() - except asyncio.CancelledError: - pass + try: + await self._timer.stop() + except asyncio.CancelledError: + pass + finally: + self._idle_event.set() def bind(self, obj: object) -> BoundAnimator: """Bind the animator to a given objects.""" diff --git a/src/textual/app.py b/src/textual/app.py index 9f1640af4..4328854ba 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -803,9 +803,11 @@ class App(Generic[ReturnType], DOMNode): terminal_size=size, ) finally: - if auto_pilot_task is not None: - await auto_pilot_task - await app._shutdown() + try: + if auto_pilot_task is not None: + await auto_pilot_task + finally: + await app._shutdown() return app.return_value @@ -1291,6 +1293,10 @@ class App(Generic[ReturnType], DOMNode): await self.animator.start() + except Exception: + await self.animator.stop() + raise + finally: await self._ready() await invoke_ready_callback() @@ -1303,10 +1309,11 @@ class App(Generic[ReturnType], DOMNode): pass finally: self._running = False - for timer in list(self._timers): - await timer.stop() - - await self.animator.stop() + try: + await self.animator.stop() + finally: + for timer in list(self._timers): + await timer.stop() self._running = True try: