From 158f51e7b335f3e7a8d6a78a654f5f868cb7e93c Mon Sep 17 00:00:00 2001 From: MaXFeeD Date: Wed, 23 Apr 2025 18:21:25 +0300 Subject: [PATCH] Properly rerun application in InteractiveSession if needed --- src/icmtoolchain/shell.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/icmtoolchain/shell.py b/src/icmtoolchain/shell.py index 4371829..062d388 100644 --- a/src/icmtoolchain/shell.py +++ b/src/icmtoolchain/shell.py @@ -184,15 +184,18 @@ class InteractiveSession(dict[str, _SCT]): dict.__init__(self, **content) def __enter__(self, *args, **kwargs) -> 'InteractiveSession[_SCT]': + is_already_running = interactive_application is not None self.application = request_application(*self.values()) - from threading import Thread - self.thread = Thread(target=lambda: self.application.run()) - self.thread.start() + if not is_already_running: + from threading import Thread + self.thread = Thread(target=lambda: self.application.run()) + self.thread.start() return self def __exit__(self, *args, **kwargs) -> None: clear_application(*self.values()) if hasattr(self, "thread"): + assert interactive_application is None self.thread.join() del self.thread