From 679e66898ea04720109868b3f9c3b8f69b11442f Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 15 Aug 2026 12:01:24 +0200 Subject: [PATCH] lib.App: Implement __aenter__() and __aexit__() __aenter__() and __aexit__() are empty stubs. Using the application as an async context manager therefore binds None in the as clause, and releases nothing on exit: an AsyncRunner created through call_async() keeps running in its thread, and since that thread is not a daemon, the process does not exit after the block. Return self from __aenter__(), and call close() from __aexit__(), so that the context manager binds the application and releases all resources on exit, whether the block exits normally or with an exception. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/App.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python/jw/pkg/lib/App.py b/src/python/jw/pkg/lib/App.py index 52cd4f15..a298c1cf 100644 --- a/src/python/jw/pkg/lib/App.py +++ b/src/python/jw/pkg/lib/App.py @@ -222,8 +222,8 @@ class App: # export self.__eloop.close() self.__eloop = None - async def __aenter__(self) -> None: - pass + async def __aenter__(self) -> App: + return self async def __aexit__( self, @@ -231,7 +231,7 @@ class App: # export exc: BaseException | None, tb: types.TracebackType | None, ) -> None: - pass + self.close() async def __run(self, argv: list[str] | None = None) -> None: