2022-03-27, 14:41
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
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:
python:import xbmc
import xbmcaddon
from lib.client import Client
SERVICE_FN='API Service'
class Service(xbmc.Monitor):
def __init__(self):
super().__init__()
self.ADDON = xbmcaddon.Addon(id='service.myservice.api-key')
self._api_key = self.ADDON.getSetting(id='api_key')
def run(self):
xbmc.log(f'{SERVICE_FN}: Running, {self._api_key}', xbmc.LOGINFO)
while not self.abortRequested():
client = Client("api.somewhere.net")
resp = client.register(self._api_key)
if resp:
xbmc.log('{SERVICE_FN}: Registration OK', xbmc.LOGINFO)
xbmc.log('{SERVICE_FN}: Sleeping', xbmc.LOGINFO)
xbmc.sleep(120000)
if __name__ == '__main__':
xbmc.sleep(2000)
service = Service()
try:
service.run()
except Exception as e:
xbmc.log(f'{SERVICE_FN}: Exception {str(e)}', xbmc.LOGFATAL)
xbmc.sleep(250)
service.waitForAbort(timeout=2)
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