cli: Fix exit traceback on Twisted based loop (e.g.; pb bridge).

This commit is contained in:
Goffi 2025-10-01 14:55:32 +02:00
commit c4d00d63da

View file

@ -33,6 +33,7 @@ from typing import Optional, Set, Union
import xml.etree.ElementTree as ET
from rich import console
from twisted.internet.error import ReactorNotRunning
from libervia.backend.core import exceptions
from libervia.backend.core.i18n import _
@ -856,7 +857,13 @@ class LiberviaCli:
except SystemExit as e:
# The loop is stopped, but we execute it one more time to call `a_quit` which
# will call any cleaning method including async ones.
asyncio.get_event_loop().run_until_complete(self.a_quit(e.code))
try:
asyncio.get_event_loop().run_until_complete(self.a_quit(int(e.code or 0)))
except ReactorNotRunning:
# This error happens with Twisted loops, we just exit cleanly. "a_quit" is
# finishing when this error is raised, so cleaning callbacks are run as
# expected.
sys.exit(e.code)
@classmethod
def run(cls):