lib.App.run_sub_commands(): Instantiate as context manager

App currently has no hook to close async resources. Call it as
context manager, so that __aexit__() gets invoked if
run_sub_commands() exits.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-15 21:21:17 +02:00
commit 3d27cc09d9

View file

@ -100,6 +100,12 @@ class App: # export
self.__eloop = None self.__eloop = None
self.__own_eloop = False self.__own_eloop = False
async def __aenter__(self) ->None:
return self
async def __aexit__(self, exc_type, exc, tb) -> None:
pass
async def __run(self, argv=None) -> None: async def __run(self, argv=None) -> None:
try: try:
@ -188,5 +194,5 @@ class App: # export
return ret return ret
def run_sub_commands(description = '', name_filter = '^Cmd.*', modules=None, argv=None): # export def run_sub_commands(description = '', name_filter = '^Cmd.*', modules=None, argv=None): # export
app = App(description, name_filter, modules) with App(description, name_filter, modules) as app:
return app.run(argv=argv) return app.run(argv=argv)