I'm building a general-purpose DBus proxy receiver that a user can leverage to configure generic signal listeners and proxy them to another service.
Therefore, I need to be able to listen to all the bus signals:
from dbus import SessionBus
def handler(*args, **kwargs):
print(args, kwargs)
# ...
bus = SessionBus()
bus.add_signal_receiver(handler, signal_name=None, dbus_interface=None, path=None)
The problem with this approach is that I have no way from the handler's args
and kwargs
to tell which interface/signal name/path are associated with the signal:
args=(dbus.String(':1.22395'), dbus.String(''), dbus.String(':1.22395')) kwargs={}
Is there an easy way to inspect DBus to get more information about the received signal? I guess that it should exist (dbus-monitor --monitor
does more or less the same thing that I'm trying to do), but I couldn't find any references online.
Look at the sender_keyword
, destination_keyword
, etc. keyword arguments of add_signal_receiver()
.
You may want to consider using pydbus, or some other more modern D-Bus binding. dbus-python is old and not very Pythonic. It’s not very actively maintained, and certainly not actively developed.