How to prevent sleep from missing an abort request?
#1
Hi,

this is the first thread I opened on the forums, but I've been reading along for a while.

Currently I am helping a fellow developer update his addon XBMC File Cleaner for Eden.
The addon deletes watched movies and episodes based upon a number of criteria and cleans up afterwards. The addon also features delayed start and scanning interval options to prevent overhead. These values are in the range from 10 to 60 minutes of sleep time.

Unfortunately I'm having some difficulty shutting down XBMC now that I have updated the addon to implement the xbmc.service hook. The code checks for abortRequested as it should, but once it enters sleep for several minutes, the abortRequested is not checked, and subsequently causes XBMC to hang upon shutdown when the addon is sleeping.

The code for my fork of his addon can be found here.

My question is: how do I prevent the addon from sleeping if an abort request comes in?

Thanks in advance,
Anthirian
Reply
#2
You need to avoid sleep for several minutes and instead either control the the interval with a ticker or look at the system time.
Another possibility would be to use the cron add-on developed by the library updater developer.

I made a quick hack (which I posted on the filecleaner github)
my version with show exception is found https://github.com/vikjon0/script.filecleaner.ext


Code:
self.service_sleep = 10

  scanInterval_ticker = self.scanInterval * 60 / self.service_sleep
  delayedStart_ticker = self.delayedStart * 60 / self.service_sleep
  ticker = 0
  delayed_completed = False
  
  while (not xbmc.abortRequested and self.deletingEnabled):
            self.reload_settings()
            if not self.deletingEnabled:
                break
            if delayed_completed == True and ticker == scanInterval_ticker:
                self.cleanup()
                ticker = 0
            elif delayed_completed == False and ticker == delayedStart_ticker:
                delayed_completed = True
                self.cleanup()
                ticker = 0
            
            time.sleep(self.service_sleep)
            ticker = ticker + 1

also, I believe you need to change

Code:
if os.path.exists(path):
   cleaningRequired = True
if self.holdingEnabled:


to
Code:
if os.path.exists(path):
   cleaningRequired = True
   if self.holdingEnabled:

to avoid error on the next run if cleaning is not enabled?
Reply
#3
Thanks for the quick reply. I will test it out when I can.

Yes, you're right about the second part, thanks.
Reply

Logout Mark Read Team Forum Stats Members Help
How to prevent sleep from missing an abort request?0