diff --git a/src/apps/fido_u2f/__init__.py b/src/apps/fido_u2f/__init__.py index 9f26320c37..4338ac70bc 100644 --- a/src/apps/fido_u2f/__init__.py +++ b/src/apps/fido_u2f/__init__.py @@ -451,7 +451,8 @@ class ConfirmState: def kill(self) -> None: if self.task is not None: workflow.onclose(self.task) - self.task.close() + loop.close(self.task) + self.task = None async def confirm(self) -> None: from trezor.ui.confirm import HoldToConfirmDialog diff --git a/src/trezor/loop.py b/src/trezor/loop.py index 412a4df022..714e018aad 100644 --- a/src/trezor/loop.py +++ b/src/trezor/loop.py @@ -65,6 +65,12 @@ def unpause(task): _paused[iface].remove(task) +def close(task): + unschedule(task) + unpause(task) + task.close() + + def run(): ''' Loop forever, stepping through scheduled tasks and awaiting I/O events @@ -259,9 +265,7 @@ class wait(Syscall): def exit(self): for task in self.scheduled: if task not in self.finished: - unpause(task) - unschedule(task) - task.close() + close(task) async def _wait(self, child): try: diff --git a/src/trezor/wire/codec_v2.py b/src/trezor/wire/codec_v2.py index b4dacf2f7e..8afed2241a 100644 --- a/src/trezor/wire/codec_v2.py +++ b/src/trezor/wire/codec_v2.py @@ -227,7 +227,7 @@ class SesssionSupervisor: def close(self, sid): if sid in self.handling_tasks: task = self.handling_tasks.pop(sid) - task.close() + loop.close(task) def newsid(self): while True: diff --git a/src/trezor/workflow.py b/src/trezor/workflow.py index 8de25da3a6..b3d27667a9 100644 --- a/src/trezor/workflow.py +++ b/src/trezor/workflow.py @@ -26,7 +26,7 @@ def closedefault(): global default if default: - default.close() + loop.close(default) default = None log.debug(__name__, 'closedefault')