altdesktop / python-dbus-next

🚌 The next great DBus library for Python with asyncio support
https://python-dbus-next.readthedocs.io/en/latest/
MIT License
187 stars 58 forks source link

on_properties_changed blocks loop.create_task until a property changes #136

Open insidewhy opened 1 year ago

insidewhy commented 1 year ago

I need to interact with a keypress handler object and call async methods on an interface so I have something like this:

loop = asyncio.get_event_loop()

def handle_keypress(key: str):
  print("got key", key)

def handle_keypress_helper(key: str) -> None
  loop.create_task(handle_keypress(key))

read_input.start(handle_keypress_helper)

If I add an on_properties_changed handler like so:

properties.on_properties_changed(on_properties_changed)

Then my key logs get blocked until a property changes. So say I press five keys, then after a property changes I finally get the logs of the five key presses.

So it looks like on_properties_changed is blocking other tasks during the wait for a property change and then they only get flushed after changes.