Skip to content

Question: Asynchronous properties? #86

@sphh

Description

@sphh

I want to wed python-dbus-next with mopidy-async-client. Since mopidy-async-client is asynchronous, I have a couple of async methods in my interface. That works fine.

When the service comes available, the sound applet is checking for its capabilities, e.g. it requests SupportedUriSchemes, which I implemented in the dbus-next interface. The problem I have, is that some of these property getters (and some setters) also use asynchronous functions of the mopdiy-async-client, e.g.:

class MopidyInterface(dbus_next.service.ServiceInterface):
    def __init__(self, mopidy):
        super().__init__('org.mpris.MediaPlayer2.Player')
        self.mopidy = mopidy

    @dbus_property(access=PropertyAccess.READ)
    def SupportedUriSchemes(self) -> 's':
        schemes = self.mopidy.core.get_uri_schemes()
        return schemes

where .get_uri_schemes() is an asynchronous method. So this does not work, because it would require an await. The error message is:

/usr/local/lib/python3.8/dist-packages/dbus_next/message_bus.py:230: RuntimeWarning: coroutine 'CoreController.get_uri_schemes' was never awaited
  body[interface.name][prop.name] = Variant(prop.signature,
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

If I change it naïvely to

    @dbus_property(access=PropertyAccess.READ)
    async def PlaybackStatus(self) -> 's':
        state = await self.mopidy.playback.get_status()
        return state.capitalize()

I get the very same error.

Is there a way to have asynchronous properties?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions