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
This commit is contained in:
parent
6a92ebce37
commit
ef837273cd
1 changed files with 6 additions and 6 deletions
|
|
@ -21,6 +21,7 @@ import asyncio
|
|||
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 @@ class QuitException(BaseException):
|
|||
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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue