question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Asynchronous properties?

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
acriscicommented, Apr 5, 2021

Let me know if that works.

1reaction
acriscicommented, Mar 29, 2021

Ok since the work is clear and I think it’s an important feature, I should get around to it soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to call an async method from a getter or setter?
An asynchronous method that returns a value. In this case, change the property to an async method. A value that can be used...
Read more >
Async/Await - Best Practices in Asynchronous Programming
The problem is that the method reads the value and suspends itself at the await, and when the method resumes it assumes the...
Read more >
How to create and use async properties - Hacking with Swift
How to create and use async properties ... Just as Swift's functions can be asynchronous, computed properties can also be asynchronous: attempting ...
Read more >
Asynchronous JavaScript - Learn web development | MDN
In this article, we'll learn about synchronous and asynchronous programming, why we often need to use asynchronous techniques, and the problems ...
Read more >
Solved For this assignment, you will need to understand - Chegg
Question : For this assignment, you will need to understand loops and the asynchronous properties of Node.js. Part 1: Looping Write a program...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found