# Porting extension to mopidy 3.x

**URL:** <https://discourse.mopidy.com/t/porting-extension-to-mopidy-3-x/3695>\
**Category:** Misc\
**Created:** [January 10, 2020, 8:19pm UTC](https://discourse.mopidy.com/t/porting-extension-to-mopidy-3-x/3695 "2020-01-10T20:19:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![avanc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/avanc/32/1061_2.png) [@avanc](https://discourse.mopidy.com/u/avanc)\
**Post date:** [January 10, 2020, 8:19pm UTC](https://discourse.mopidy.com/t/porting-extension-to-mopidy-3-x/3695/1 "2020-01-10T20:19:32Z")

</div>

I’m going to prt my simple headless extension to mopidy 3.0:

> **[avanc/mopidy-headless](https://github.com/avanc/mopidy-headless)**
>
> Control Mopidy with generic input devices. Contribute to avanc/mopidy-headless development by creating an account on GitHub.

I had to replace

```
for playlist in self.core.playlists.playlists.get():
    self.playlists.append(playlist)

```

with

```
for playlist in self.core.playlists.as_list():
    self.playlists.append(playlist)

```

Documentation says, that as\_list() returns a list of Ref objects: [https://docs.mopidy.com/en/latest/api/core/#mopidy.core.PlaylistsController.as\_list](https://docs.mopidy.com/en/latest/api/core/#mopidy.core.PlaylistsController.as_list)

However, logger.debug(self.core.playlists.as\_list()) returns

```
DEBUG 2020-01-10 21:18:46,021 [97165:InputFrontend-9] mopidy_headless.frontend
  <pykka._threading.ThreadingFuture object at 0x7f4b7c32b9a0>

```

Why it is a ThreadingFuture and not a Python list?

---

<div class="post-metadata">

**Author:** ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)\
**Post date:** [January 10, 2020, 8:27pm UTC](https://discourse.mopidy.com/t/porting-extension-to-mopidy-3-x/3695/2 "2020-01-10T20:27:27Z")

</div>

Great to hear that you’re porting another extension to Python 3 🙂

**Short story:** You need to change `.as_list()` to `.as_list().get()` to get the actual value out of the future object.

**Long story:** Mopidy uses an actor library called [Pykka](https://www.pykka.org/). `self.core` is a reference to an `ActorProxy` for Mopidy’s core “actor”, which runs in another thread than your extension code. All methods on the proxy object returns “futures” for some result that is being concurrently calculated in the other thread. By calling one of the methods and getting a future, the extension’s thread sends a message to the core thread to ask it to do its work and return the result. However, the extension isn’t blocked waiting for the result, it immediately receives a future, which is a handle for the result that will be available one time in the future. Once you call `.get()` on the future, the extension’s thread blocks everything it is doing until the core API method’s return value is available in the future.

Pykka is a quite small library with good documentation if you want to get more into this.

---

<div class="post-metadata">

**Author:** ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)\
**Post date:** [January 10, 2020, 8:28pm UTC](https://discourse.mopidy.com/t/porting-extension-to-mopidy-3-x/3695/3 "2020-01-10T20:28:37Z")

</div>

By the way, if your extension is of general usefulness, i.e. can be useful for others than yourself, please feel free to add it to the new [Mopidy extension registry](https://mopidy.com/ext/) once you’ve updated it to work with Mopidy 3 and Python 3.

---

<div class="post-metadata">

**Author:** ![avanc](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/avanc/32/1061_2.png) [@avanc](https://discourse.mopidy.com/u/avanc)\
**Post date:** [January 10, 2020, 8:57pm UTC](https://discourse.mopidy.com/t/porting-extension-to-mopidy-3-x/3695/4 "2020-01-10T20:57:47Z")

</div>

Thanks for the explanation. This helped a lot.
