2023-08-18, 18:15
Hi,
I wrote a legal video addon for a local TV broadcaster. The code is awful, because I am a noob at this, but so far I got everything I wanted done.
However I am using Kodi settings to store login tokens and other values I obtain during the login process. I know this is somewhat of an abuse of the Kodi settings, but when I tried ORMs, they all failed me since on a certain Kodi 20.x version the built-in sqlite module's close method caused a deadlock and so the whole python interpreter hung. Since I want to support all recent 20.x versions I decided to ditch the idea of using sqlite. Settings also has the nice benefit that I can have disabled values so the user can see their tokens if they want to.
But I also use services and threads in order to do certain tasks such as playback reporting, a small web service and timed EPG exporting.
The latter has problems. When Kodi starts, my service is spawned which makes sure that the login is successful by calling an authorize method and spawns a thread that periodically grabs the EPG. So far so good, this works normally. However if authorize() figures that the access token expired and obtains a new one, it tries to save these in settings and that never seems to happen. Here is the code that sets it. https://github.com/movieshark/VodkaTV/bl...#L285-L288
If I put an xbmc.log call right before those setSettings, I can see that it runs. Therefore setSetting is the culprit. It doesn't save the new values.
When I open the addon and it runs in foreground, it calls the same authorize method and the new token gets correctly saved.
So what am I doing wrong?
Is setSetting not thread safe? Or is it not supposed to be used from services?
I wrote a legal video addon for a local TV broadcaster. The code is awful, because I am a noob at this, but so far I got everything I wanted done.
However I am using Kodi settings to store login tokens and other values I obtain during the login process. I know this is somewhat of an abuse of the Kodi settings, but when I tried ORMs, they all failed me since on a certain Kodi 20.x version the built-in sqlite module's close method caused a deadlock and so the whole python interpreter hung. Since I want to support all recent 20.x versions I decided to ditch the idea of using sqlite. Settings also has the nice benefit that I can have disabled values so the user can see their tokens if they want to.
But I also use services and threads in order to do certain tasks such as playback reporting, a small web service and timed EPG exporting.
The latter has problems. When Kodi starts, my service is spawned which makes sure that the login is successful by calling an authorize method and spawns a thread that periodically grabs the EPG. So far so good, this works normally. However if authorize() figures that the access token expired and obtains a new one, it tries to save these in settings and that never seems to happen. Here is the code that sets it. https://github.com/movieshark/VodkaTV/bl...#L285-L288
If I put an xbmc.log call right before those setSettings, I can see that it runs. Therefore setSetting is the culprit. It doesn't save the new values.
When I open the addon and it runs in foreground, it calls the same authorize method and the new token gets correctly saved.
So what am I doing wrong?
Is setSetting not thread safe? Or is it not supposed to be used from services?