2014-05-28, 09:18
I've been looking at a few "service" type addons, and as far as I can tell in order for xbmc.Monitor to function properly, and for it's notifications to be "consumed", xbmc.sleep() needs to be called at some point.
And in order for xbmc.abortRequested to be actioned in a timely manner, xbmc.sleep() needs to be called fairly frequently.
So, what you end up with is this:
which on a low powered device is wasteful as the thread is waking up 10 times a second and spinning around doing pretty much nothing.
Without the call to xbmc.sleep(), no xbmc.Monitor notification events are consumed. With a long xbmc.sleep(), events are consumed correctly, but now xbmc.abortRequested is not actioned fast enough during a shutdown.
Ideally what is needed is a very long (or even infinite) sleep() that can be interrupted whenever an abort occurs:
Could the xbmc object be made to terminate the call to sleep() whenever an abort occurs?
Maybe a new method, xbmc.wake(), could be used to terminate the current threads call to xbmc.sleep(), with xbmc.wake() being called in xbmc.Monitor::onAbortRequested(). Or for that matter, it could be called by any of the other xbmc.Monitor event handlers.
This would be much more efficient than continuously waking up many times a second to check if anything needs to be done.
And in order for xbmc.abortRequested to be actioned in a timely manner, xbmc.sleep() needs to be called fairly frequently.
So, what you end up with is this:
Code:
class MyMonitorClass(xbmc.Monitor):
def __init__( self, *args, **kwargs ):
xbmc.Monitor.__init__(self)
def onNotification(self, sender, method, data):
...
def onScreensaverActivated(self):
...
def onAbortRequested(self):
...
monitor = MyMonitorClass()
while not xbmc.abortRequested:
xbmc.sleep(100) # process event notifications, check if aborted 10 times a second
which on a low powered device is wasteful as the thread is waking up 10 times a second and spinning around doing pretty much nothing.
Without the call to xbmc.sleep(), no xbmc.Monitor notification events are consumed. With a long xbmc.sleep(), events are consumed correctly, but now xbmc.abortRequested is not actioned fast enough during a shutdown.
Ideally what is needed is a very long (or even infinite) sleep() that can be interrupted whenever an abort occurs:
Code:
while not xbmc.abortRequested:
xbmc.sleep(-1) # sleep forever, or until interrupted
Could the xbmc object be made to terminate the call to sleep() whenever an abort occurs?
Maybe a new method, xbmc.wake(), could be used to terminate the current threads call to xbmc.sleep(), with xbmc.wake() being called in xbmc.Monitor::onAbortRequested(). Or for that matter, it could be called by any of the other xbmc.Monitor event handlers.
This would be much more efficient than continuously waking up many times a second to check if anything needs to be done.