Properly rerun application in InteractiveSession if needed

This commit is contained in:
MaXFeeD
2025-04-23 18:21:25 +03:00
parent f4f52ae041
commit 158f51e7b3
+6 -3
View File
@@ -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