changeset 4141:ba8ddfdd334f

cli (loops): run GLib loop in same thread as asyncio: use the new `install_glib_asyncio_iteration` to run GLib in the same thread as asyncio. rel 426
author Goffi <goffi@goffi.org>
date Wed, 01 Nov 2023 14:05:53 +0100
parents 13dd5660c28f
children 783bbdbf8567
files libervia/cli/loops.py
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/cli/loops.py	Wed Nov 01 14:04:25 2023 +0100
+++ b/libervia/cli/loops.py	Wed Nov 01 14:05:53 2023 +0100
@@ -21,6 +21,7 @@
 import logging as log
 from libervia.backend.core.i18n import _
 from libervia.cli.constants import Const as C
+from libervia.frontends.tools import aio
 
 log.basicConfig(level=log.WARNING,
                 format='[%(name)s] %(message)s')
@@ -38,23 +39,22 @@
 def get_libervia_cli_loop(bridge_name):
     if 'dbus' in bridge_name:
         import signal
-        import threading
-        from gi.repository import GLib
 
         class LiberviaCLILoop:
 
+            def __init__(self):
+                self.loop = loop = asyncio.get_event_loop()
+
             def run(self, libervia_cli, args, namespace):
+                aio.install_glib_asyncio_iteration()
                 signal.signal(signal.SIGINT, self._on_sigint)
-                self._glib_loop = GLib.MainLoop()
-                threading.Thread(target=self._glib_loop.run).start()
-                loop = asyncio.get_event_loop()
+                loop = self.loop
                 loop.run_until_complete(libervia_cli.main(args=args, namespace=namespace))
                 loop.run_forever()
 
             def quit(self, exit_code):
                 loop = asyncio.get_event_loop()
                 loop.stop()
-                self._glib_loop.quit()
                 sys.exit(exit_code)
 
             def call_later(self, delay, callback, *args):