Kodi Community Forum
Can't get service addon to stop from XBMC - 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)
+--- Thread: Can't get service addon to stop from XBMC (/showthread.php?tid=123492)

Can't get service addon to stop from XBMC - Gujs - 2012-02-20


I am trying to extend service addons in openelec system. I am trying to implement possibility to stop service addon when it is disabled by user. This way we would also gain a restart of service addon when it is upgraded. Right now our user have to reboot if they upgrade service addons which are made by openelec maintainers.

I thought I can do this by using xbmc.abortRequested in the default.py but I found out that xbmc closes python to fast to process all the code after.

Here is the code I use:
import xbmc, time, os, subprocess

__scriptname__ = "HTS TVheadend Service"
__author__ = "OpenELEC"
__url__ = "http://www.openelec.tv"
__settings__   = xbmcaddon.Addon(id='service.multimedia.hts-tvheadend')
__cwd__        = __settings__.getAddonInfo('path')
__path__       = xbmc.translatePath( os.path.join( __cwd__, 'bin', "tvheadend.service") )

subprocess.Popen("chmod -R +x " + __cwd__ + "/bin/*" , shell=True, close_fds=True)
subprocess.Popen(__path__, shell=True, close_fds=True)

while (not xbmc.abortRequested):

a = 0
while a < 100:
  a = a + 1
  print a

subprocess.Popen("killall tvheadend", shell=True, close_fds=True)

I added while counter just for checking why thing are not working. This code should shutdown tvheadend process when I disable tvheadend service addon in addon information. But instead of that it even doesn't get to that part of code, mostly python thread is already closed when counter counts to 5.

Here is the part of log when I try to disable the addon:
22:17:18 T:140226833254208   DEBUG: LIRC: Update - NEW at 5177093:160 0 KEY_OK devinput (KEY_OK)
22:17:18 T:140226833254208   DEBUG: OnKey: 11 (0b) pressed, action is Select
22:17:18 T:140226833254208    INFO: Stopping script with id: 10
22:17:18 T:140226833254208   DEBUG: CGUIMediaWindow::GetDirectory (addons://enabled/xbmc.service)
22:17:18 T:140226833254208   DEBUG:   ParentPath = [addons://enabled/xbmc.service]
22:17:18 T:140226485786368  NOTICE: 1
22:17:18 T:140226485786368  NOTICE: 2
22:17:18 T:140226485786368  NOTICE: 3
22:17:18 T:140226485786368  NOTICE: 4
22:17:18 T:140226485786368  NOTICE: 5
22:17:18 T:140226485786368    INFO: Scriptresult: Aborted
22:17:18 T:140226477393664  NOTICE: Thread Jobworker start, auto delete: true
22:17:18 T:140226485786368    INFO: Python script interrupted by user
22:17:18 T:140226485786368   DEBUG: Thread XBPyThread 140226485786368 terminating
22:17:18 T:140226477393664   ERROR: ADDON: extension 'downloader/' is not currently supported for service addon
22:17:18 T:140226485786368   ERROR: Previous line repeats 1 times.
22:17:18 T:140226485786368  NOTICE: Thread Background Loader start, auto delete: false
22:17:18 T:140226485786368   DEBUG: Thread Background Loader 140226485786368 terminating
22:17:18 T:140226833254208   DEBUG: SECTION:LoadDLL(special://xbmcbin/system/ImageLib-x86_64-linux.so)
22:17:18 T:140226833254208   DEBUG: Loading: /usr/lib/xbmc/system/ImageLib-x86_64-linux.so
22:17:18 T:140226833254208   DEBUG: waiting for python thread 10 to stop
22:17:18 T:140226833254208   DEBUG: python thread 10 destructed
22:17:18 T:140226833254208   DEBUG: LIRC: Update - NEW at 5177363:160 0 KEY_OK_UP devinput (KEY_OK_UP)

I would like to know if I am doing something wrong or I just found an xbmc bug on service addons. I would really appreciate some help from experts on this filed.

PS: Sorry for posting on the wrong forum section. Please move to Python Script and Plugin Addon Development. Thank You.

- giftie - 2012-02-21

I think this has been fixed in the master -> https://github.com/xbmc/xbmc/commit/e6bf089bbf486c9879d3abc5ce31a99b67558ea7

- Gujs - 2012-02-21

Thanks. I hope it will be back-ported to Eden branch :-)