From 29cca614f00da48835e897210197ad15260a760e Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Thu, 22 Aug 2019 17:23:35 +0200 Subject: [PATCH] core/workflow: properly reset the default task global --- core/src/trezor/workflow.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/src/trezor/workflow.py b/core/src/trezor/workflow.py index 7d2f6aa5a8..9d5f615aef 100644 --- a/core/src/trezor/workflow.py +++ b/core/src/trezor/workflow.py @@ -54,13 +54,21 @@ def start_default(constructor: Callable[[], loop.Task]) -> None: if not default_task: default_constructor = constructor default_task = constructor() - loop.schedule(default_task) + + # Schedule the default task. Because the task can complete on its own, + # we need to reset the `default_task` global in a finalizer. + loop.schedule(default_task, None, None, _finalize_default) def close_default() -> None: """Explicitly close the default workflow task.""" + if default_task: + # We let the `_finalize_default` reset the global. + loop.close(default_task) + + +def _finalize_default(task, value) -> None: global default_task - if default_task: - loop.close(default_task) + if default_task is task: default_task = None