Plugin using asyncio

Is there any guidelines/examples on how to use asyncio in a plugin? I am the dev for GitHub - cameroncros/OctoPrint-DiscordRemote: Discord plugin for OctoPrint and I am having trouble using which uses asyncio. Because I cannot get access to the main event loop, I am not quite sure how to start things properly. Any guidance/suggestions would be appreciated.

This TP Link plugin is the best example I have for you. It's on my list to learn as well (for WLED plugin) but have not had time yet.

Be aware you may have to drop Python 2 support to get access to most asyncio stuff (and the async keyword) though. Stats on adoption can be found at - 1.7.0 has an annoying warning about upgrading so we might see the pace pick up there.

1 Like

I dont mind dropping 1.x support, there is the existing plugin for that if people really want to stay in 1.x land. I am just sick on maintaining my own home-baked discord impl, which barely works at the best of times.

I will check out the tplink plugin, thanks for that, and thanks for the link, I was looking for that for ages and couldnt find it.

Here's another asyncio plugin example.

1 Like

Yeah of course, if it makes your life easier then drop Python 2. I was just making sure you were aware - it should be doable, but you might get quite a few people complaining if they can't install it.

Setting python_requires means that pip will prevent the installs - it's what we're recommending for most Py3 only plugins since it gives a message that at least some people can understand themselves and don't bother you. OctoPrint 1.7.0 can read this error and provides users with a better explanation and link to an FAQ

1 Like

Definitely will do the python version limit. I will checkout your examples and see if I can adapt them for my code, thanks!