From c39ba83c8b307e4b41ad3d99fa04c3129f5dae91 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 5 Aug 2024 15:47:17 +0200 Subject: [PATCH] fix(core/debug): make sure return_layout_change does not crash on a race condition [no changelog] --- core/src/apps/debug/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/apps/debug/__init__.py b/core/src/apps/debug/__init__.py index 3f08be81af..bd80af92d6 100644 --- a/core/src/apps/debug/__init__.py +++ b/core/src/apps/debug/__init__.py @@ -127,10 +127,13 @@ if __debug__: return content - async def return_layout_change() -> None: + async def return_layout_change() -> None: # type: ignore [Return type of async generator] content_tokens = await get_layout_change_content() - assert isinstance(DEBUG_CONTEXT, context.Context) + # spin for a bit until DEBUG_CONTEXT becomes available + while not isinstance(DEBUG_CONTEXT, context.Context): + yield # type: ignore [Return type of async generator] + if storage.layout_watcher is LAYOUT_WATCHER_LAYOUT: await DEBUG_CONTEXT.write(DebugLinkLayout(tokens=content_tokens)) else: