lib.App: Refactor App / Cmd to adress multiple functionality and style issues #60

Merged
Jan Lindemann merged 12 commits from jan/fix/20260815-lib-app-cmd-refactor-multiple-functionality-and-style-issues into master 2026-08-15 16:07:54 +02:00 AGit
Showing only changes of commit 679e66898e - Show all commits

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>
Jan Lindemann 2026-08-15 12:01:24 +02:00
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -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: