2012-01-10, 18:10
I'm currently the author for the XBMC Library Auto Update addon. For Eden I changed the type of addon to use the 'xbmc.service' extension.
Everything works pretty well except for when you try to quit XBMC. The service itself is really pretty simple (see code snippet below). It just checks every 60 seconds if it should run the library update or not based on the last time it ran. If the close signal (xbmc.abortRequested) is set then the service exits. The issue is that if you try to close XBMC and there is still say 30 seconds left on the thread sleep operation XBMC will hang for those 30 seconds until the service exits before the program will shut down.
I've been trying to think of a "graceful" way to handle this without having the thread sleep operation reduced needlessly to a small amount of time like 5 or 10 seconds. If anyone has any ideas on how this could be done better please let me know. It isn't a big issue but there must be a way it could be done better. Thanks in advance for any advice.
Everything works pretty well except for when you try to quit XBMC. The service itself is really pretty simple (see code snippet below). It just checks every 60 seconds if it should run the library update or not based on the last time it ran. If the close signal (xbmc.abortRequested) is set then the service exits. The issue is that if you try to close XBMC and there is still say 30 seconds left on the thread sleep operation XBMC will hang for those 30 seconds until the service exits before the program will shut down.
I've been trying to think of a "graceful" way to handle this without having the thread sleep operation reduced needlessly to a small amount of time like 5 or 10 seconds. If anyone has any ideas on how this could be done better please let me know. It isn't a big issue but there must be a way it could be done better. Thanks in advance for any advice.
Code:
while(not xbmc.abortRequested):
now = time.time()
timer_amounts = {}
timer_amounts['0'] = 1
timer_amounts['1'] = 2
timer_amounts['2'] = 5
timer_amounts['3'] = 10
timer_amounts['4'] = 15
timer_amounts['5'] = 24
#only do this if we are not playing anything
if(xbmc.Player().isPlaying() == False and now > self.last_run + (timer_amounts[Addon.getSetting('timer_amount')] * 60 * 60)):
#run the update since we have just started the program
if(Addon.getSetting('update_video') == 'true'):
xbmc.log('Updating Video')
xbmc.executebuiltin('UpdateLibrary(video)')
if(Addon.getSetting('update_music') == 'true'):
xbmc.log('Updating Music')
xbmc.executebuiltin('UpdateLibrary(music)')
#reset the last run timer
self.last_run = now
xbmc.log("Update Library will run again in " + str(timer_amounts[Addon.getSetting("timer_amount")]) + " hours")
#put the thread to sleep for x number of seconds
time.sleep(60)