{"action":"created","issue":{"url":"https://api.github.com/repos/hyperion-project/hyperion.kodi/issues/30","repository_url":"https://api.github.com/repos/hyperion-project/hyperion.kodi","labels_url":"https://api.github.com/repos/hyperion-project/hyperion.kodi/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/hyperion-project/hyperion.kodi/issues/30/comments","events_url":"https://api.github.com/repos/hyperion-project/hyperion.kodi/issues/30/events","html_url":"https://github.com/hyperion-project/hyperion.kodi/issues/30","id":188659414,"number":30,"title":"Delay when exiting Kodi","user":{"login":"jessie-github","id":22061570,"avatar_url":"https://avatars.githubusercontent.com/u/22061570?v=3","gravatar_id":"","url":"https://api.github.com/users/jessie-github","html_url":"https://github.com/jessie-github","followers_url":"https://api.github.com/users/jessie-github/followers","following_url":"https://api.github.com/users/jessie-github/following{/other_user}","gists_url":"https://api.github.com/users/jessie-github/gists{/gist_id}","starred_url":"https://api.github.com/users/jessie-github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jessie-github/subscriptions","organizations_url":"https://api.github.com/users/jessie-github/orgs","repos_url":"https://api.github.com/users/jessie-github/repos","events_url":"https://api.github.com/users/jessie-github/events{/privacy}","received_events_url":"https://api.github.com/users/jessie-github/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-11T00:54:18Z","updated_at":"2016-12-17T08:52:51Z","closed_at":null,"body":"I noticed the following error when closing kodi:\r\n```\r\nERROR: CPythonInvoker(0, /home/user/.kodi/addons/script.service.hyperion-master/addon.py): script didn't stop in 5 seconds - let's kill it\r\nWARNING: CPythonInvoker(0, /home/user/.kodi/addons/script.service.hyperion-master/addon.py): the python script \"/home/user/.kodi/addons/script.service.hyperion-master/addon.py\" has left several classes in memory that we couldn't clean up. The classes include: N14PythonBindings31XBMCAddon_xbmc_Monitor_DirectorE,N9XBMCAddon4xbmc6PlayerE\r\n```\r\n\r\nClass cleanup can be solved by using weakref in settings.py:\r\n```python\r\nimport weakref\r\nimport xbmc\r\nimport xbmcaddon\r\n\r\nfrom misc import log\r\n\r\nclass MyMonitor (xbmc.Monitor):\r\n\t'''Class to capture changes in settings and screensaver state\r\n\t'''\r\n\t\r\n\tdef __init__(self, settings):\r\n\t\txbmc.Monitor.__init__(self)\r\n\t\tself.__settings = weakref.ref(settings)\r\n\t\tself.__settings().screensaver = xbmc.getCondVisibility(\"System.ScreenSaverActive\")\r\n\t\tself.__settings().abort = xbmc.abortRequested\r\n\r\n\tdef onAbortRequested(self):\r\n\t\tself.__settings().abort = False\r\n\t\t\r\n\tdef onSettingsChanged(self):\r\n\t\tself.__settings().readSettings()\r\n\t  \r\n\tdef onScreensaverDeactivated(self):\r\n\t\tself.__settings().screensaver = False\r\n\t  \r\n\tdef onScreensaverActivated(self):    \r\n\t\tself.__settings().screensaver = True\r\n```\r\n\r\nAnd the delay before closing can be solved by using waitForAbort in settings.py:\r\n```python\r\nclass MyMonitor (xbmc.Monitor):\r\n\t'''Class to capture changes in settings and screensaver state\r\n\t'''\r\n\t\r\n\tdef __init__(self, settings):\r\n\t\txbmc.Monitor.__init__(self)\r\n\t\tself.__settings = weakref.ref(settings)\r\n\t\tself.__settings().screensaver = xbmc.getCondVisibility(\"System.ScreenSaverActive\")\r\n\t\tself.__settings().abort = xbmc.abortRequested\r\n\t\tself.__settings().waitForAbort = self.waitForAbort\r\n```\r\nand in addon.py:\r\n```python\r\nimport xbmc\r\nimport xbmcaddon\r\nimport xbmcgui\r\nimport os\r\n\r\n# Add the library path before loading Hyperion\r\n__addon__      = xbmcaddon.Addon()\r\n__cwd__        = __addon__.getAddonInfo('path')\r\nsys.path.append(xbmc.translatePath(os.path.join(__cwd__, 'resources', 'lib')))\r\n\t\t\r\nfrom settings import Settings\r\nfrom state import DisconnectedState\r\n\r\nif  __name__ == \"__main__\":\r\n\t# read settings\r\n\tsettings = Settings()\r\n\r\n\t# initialize the state\r\n\tstate = DisconnectedState(settings)\r\n\t\r\n\t# start looping\r\n\twhile not settings.abort:\r\n\t\t# execute the current state\r\n\t\tnext_state = state.execute()\r\n\t\t\r\n\t\t# delete the old state if necessary\r\n\t\tif state != next_state:\r\n\t\t\tdel state\r\n\t\t\t\r\n\t\t# advance to the next state\r\n\t\tstate = next_state\r\n\t\tif settings.waitForAbort(0.001):\r\n\t\t\tbreak\r\n\t\t\r\n\t# clean up the state closing the connection if present\r\n\tdel state\r\n\tdel settings\r\n```\r\n\r\nI only had a very quick look because the delay before closing (>5 seconds) was becoming to be annoying. However I am not sure at all of what I have done, so be careful with this code."},"comment":{"url":"https://api.github.com/repos/hyperion-project/hyperion.kodi/issues/comments/267751387","html_url":"https://github.com/hyperion-project/hyperion.kodi/issues/30#issuecomment-267751387","issue_url":"https://api.github.com/repos/hyperion-project/hyperion.kodi/issues/30","id":267751387,"user":{"login":"jessie-github","id":22061570,"avatar_url":"https://avatars.githubusercontent.com/u/22061570?v=3","gravatar_id":"","url":"https://api.github.com/users/jessie-github","html_url":"https://github.com/jessie-github","followers_url":"https://api.github.com/users/jessie-github/followers","following_url":"https://api.github.com/users/jessie-github/following{/other_user}","gists_url":"https://api.github.com/users/jessie-github/gists{/gist_id}","starred_url":"https://api.github.com/users/jessie-github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jessie-github/subscriptions","organizations_url":"https://api.github.com/users/jessie-github/orgs","repos_url":"https://api.github.com/users/jessie-github/repos","events_url":"https://api.github.com/users/jessie-github/events{/privacy}","received_events_url":"https://api.github.com/users/jessie-github/received_events","type":"User","site_admin":false},"created_at":"2016-12-17T08:52:51Z","updated_at":"2016-12-17T08:52:51Z","body":"@WoLpH I am not so worried about the weakrefs. But the waitForAbort is really dirty. I had to put a very small value otherwise there is a long delay before LED update. It works for me because the computer is very fast but it may not work for slower computers ? I haven't found any other solution though."}}
{"actor":{"display_login":"jessie-github"}}