From c4d00d63da29ef05879020d597dcf700db412c4a Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 1 Oct 2025 14:55:32 +0200 Subject: [PATCH] cli: Fix exit traceback on Twisted based loop (e.g.; `pb` bridge). --- libervia/cli/base.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libervia/cli/base.py b/libervia/cli/base.py index bf89aef0..97139381 100644 --- a/libervia/cli/base.py +++ b/libervia/cli/base.py @@ -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):