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 <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-08-15 12:01:24 +02:00
commit 679e66898e
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -222,8 +222,8 @@ class App: # export
self.__eloop.close() self.__eloop.close()
self.__eloop = None self.__eloop = None
async def __aenter__(self) -> None: async def __aenter__(self) -> App:
pass return self
async def __aexit__( async def __aexit__(
self, self,
@ -231,7 +231,7 @@ class App: # export
exc: BaseException | None, exc: BaseException | None,
tb: types.TracebackType | None, tb: types.TracebackType | None,
) -> None: ) -> None:
pass self.close()
async def __run(self, argv: list[str] | None = None) -> None: async def __run(self, argv: list[str] | None = None) -> None: