Service addons, background tasks in "sync" or "async" context. - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +---- Forum: Python 3 migration (https://forum.kodi.tv/forumdisplay.php?fid=281) +---- Thread: Service addons, background tasks in "sync" or "async" context. (/showthread.php?tid=367628) |
Service addons, background tasks in "sync" or "async" context. - x-stride - 2022-03-27 Hello all, Trying to get this right, but it seems I got something wrong. Any help appreciated! Background task in "sync" context Wanting to make a HTTP call every 2 minutes in a Client with urllib3:
My Client in lib.client is not using any asyncio, and is only using xbmc.log() for logging. What am I missing here? Disabling or stopping the service locks up the GUI probably caused by xbmc.sleep(120000). I made some tests with an asyncio implementation too, but ran into the same problem. /x-stride RE: Service addons, background tasks in "sync" or "async" context. - x-stride - 2022-03-27 (2022-03-27, 14:41)x-stride Wrote: Trying to get this right, but it seems I got something wrong. Any help appreciated! Made an similar asyncio websockets echo client: A bit overkill in some places maybe
The async part behaves as expected. Same behaviour when it comes to killing it, updating it, GUI becoming locked. Needed asyncio websockets so added it. https://github.com/x-stride/script.module.websockets https://github.com/x-stride/service.websockets.echo /x-stride /x-string RE: Service addons, background tasks in "sync" or "async" context. - Roman_V_M - 2022-08-26 asyncio is currently cannot be used in Kodi due to underlying Python limitation regarding asyncio support in sub-interpreters. Basically, only one addon can run asyncio event loop, other will fail when trying to do this. See my comment below. RE: Service addons, background tasks in "sync" or "async" context. - Roman_V_M - 2022-08-27 Currently in Kodi you can only use a pure-Python asyncio implementation because of the underlying CPython bug. To be able to use asyncio in Kodi addons you need to apply the following workaround at the beginning of your Python module that uses asyncio:
|