mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +02:00
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:
parent
4f17a9cc93
commit
3d27cc09d9
1 changed files with 8 additions and 2 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue