Skip to content

Instantly share code, notes, and snippets.

@mbenford
Created June 13, 2021 22:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbenford/0e9a5240246bc2ff7cb5114c94508f45 to your computer and use it in GitHub Desktop.
Save mbenford/0e9a5240246bc2ff7cb5114c94508f45 to your computer and use it in GitHub Desktop.
Monitoring DBus with dbus-next
from dbus_next.aio import MessageBus
from dbus_next.message import Message
from dbus_next.constants import BusType
import asyncio
async def main():
match = (
"type='method_call',"
"interface='org.freedesktop.PowerManagement.Inhibit',"
"path='/org/freedesktop/PowerManagement/Inhibit'"
)
bus = await MessageBus(bus_type=BusType.SESSION).connect()
await bus.call(Message(
destination="org.freedesktop.DBus",
path="/org/freedesktop/DBus",
interface="org.freedesktop.DBus.Monitoring",
member="BecomeMonitor",
signature="asu",
body=[[match], 0],
serial=bus.next_serial(),
))
bus.add_message_handler(handler)
def handler(message):
print(message.member)
return True
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment