I'm using pygattlib to interface with Bluetooth device in Python. It works just fine, but the problem occurs when I try to use DBus in my code.
If I import gattlib
and GLib.MainLoop().run()
, the program freezes when calling run()
.
I found that gattlib has its own MainLoop for internal async calls.
I didn't find anything that would cover this specific issue, just some examples of having multiple mainloops in C.
This is the relevant part of the Python code:
import gattlib as bt
try:
from gi.repository import GLib
except ImportError:
import glib as GLib
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
[...do stuff with gattlib here...]
DBusGMainLoop(set_as_default=True)
dbusService = SystemDBus()
try:
loop = GLib.MainLoop()
loop.run() # it stalls here, doesn't respond to DBus or anything
except KeyboardInterrupt:
GLib.MainLoop().quit()