methods to reload service ?
#1
Brick 
just wondering what methods exist to reload a service based
Code:
onSettingsChanged()
?
Thanks !
clearArt Concept
cdArt Concept

*If like, thank user
Reply
#2
I've probably been doing it all wrong (so I'll be interested in any other answers to this thread!) but my approach was that I didn't want to restart the service, instead, I wanted the new settings to have effect from that point.

All I ended up doing was just reloading the settings in the service loop and updating variables as necessary.

It's not big, it's not clever, but it works for me.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#3
here's what i use to load new settings:

PHP Code:
class Main:
    
def __init__self ):
        
self._service_setup()
        while (
not self.Monitor.abortRequested()):
            
# rest of your code here
            
xbmc.sleep(1000)

    
def _service_setupself ):
        
self.Monitor MyMonitor(action self._get_settings)
        
self._get_settings

    def _get_settings
self ):
        
self.user __addon__.getSetting('username')
        
self.pass __addon__.getSetting('password')

class 
MyMonitor(xbmc.Monitor):
    
def __init__self, *args, **kwargs ):
        
xbmc.Monitor.__init__self )
        
self.action kwargs['action']

    
def onSettingsChangedself ):
        
self.action() 
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#4
Maybe it's time to change my code... That's far more professional than my "solution"!

Thanks for sharing, ronie.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#5
thank ronie, I would try that !

I would think there was a kodi method to do that like
Ex.(made up)
Code:
xbmc.Addon().reloadAddon()
or something instead of reloading variables and settings individually.
clearArt Concept
cdArt Concept

*If like, thank user
Reply
#6
Need some help. I can't seem to get Kodi to recognize settings being changed. There doesn't seem to be an event created when they change. I've called the onSettingsChanged() routine directly and it works so there shouldn't be an error its getting caught on. The main program just chugs along and there aren't any logs written from the restart routine.

Any ideas what I might be doing wrong? Here's the code below.

Code:
class  Main:
    def __init__(self):  
        self._reset = False            #Reset used to kill threaded loops in main program
        self.Monitor = MyMonitor(action = self.restart)
        self.start()

    def restart(self):
        common.log_verbose("A setting change has been detected!")
        self._reset = False    
        common.log_normal("Applying changed settings in 10 seconds")
        self.Monitor.waitForAbort(10)
        self._reset = True
        self.start()
  
    def start(self):
    
        #Main Code here

        
class MyMonitor(xbmc.Monitor):
    def __init__(self, *args, **kwargs):
        xbmc.Monitor.__init__(self)
        self.action = kwargs['action']
        
    def onSettingsChanged(self):
        self.action()
  
  
      
if __name__ == '__main__':
    Main()
Reply
#7
I'll post this here for other people. I solve my problem. In the main code I was threading. In each of those threads they looped. But the main thread ends so I had to add a loop that doesn't do anything at the end of the code to keep the monitor alive to act on settings changes. I figured it out on a fluke when I accidentally killed the thread initializing.

Code:
class  Main:
     def __init__(self):  
         self._reset = False            #Reset used to kill threaded loops in main program
         self.Monitor = MyMonitor(action = self.restart)
         self.start()

     def restart(self):
         common.log_verbose("A setting change has been detected!")
         self._reset = False    
         common.log_normal("Applying changed settings in 10 seconds")
         self.Monitor.waitForAbort(10)
         self._reset = True
         self.start()
    
     def start(self):
    
         #Main Code here - Started threads that looped.  This didn't work until the loop was added below - even though I had other loops processing.  

         while not self.Monitor.abortRequested():
             xbmc.sleep(1000)

        
class MyMonitor(xbmc.Monitor):
     def __init__(self, *args, **kwargs):
         xbmc.Monitor.__init__(self)
         self.action = kwargs['action']
        
     def onSettingsChanged(self):
         self.action()
    
    
        
if __name__ == '__main__':
     Main()
Reply

Logout Mark Read Team Forum Stats Members Help
methods to reload service ?0