OpenELEC / service.openelec.settings

service.openelec.settings - OpenELEC settings addon
Other
12 stars 35 forks source link

Eliminate xbmc.sleep(100) #43

Closed MilhouseVH closed 10 years ago

MilhouseVH commented 10 years ago

https://github.com/OpenELEC/service.openelec.settings/blob/master/service.py#L147

Just wondering if this is really necessary, what is it for - just to tell if xbmc.abortRequested is True?

Couldn't a blocking read from a queue be used here, with something stuffed into the queue during cxbmcm.onAbortRequested(), which would mean the main thread only "wakes" when the abort has occurred, and sleeps (blocks) at all other times?

I know it's only waking 10 times a second, but this seems to account for about 1-2% CPU on a 1GHz Pi (hard to say exactly, but it's noticeably lower when not waking every 1/10th second).

Can work on a PR if you think this is valid.

MilhouseVH commented 10 years ago

Closing this, as it appears that xbmc.sleep() is not the same as time.sleep() and is designed for event propagation as much as anything - without it, events will never be issued to listeners.

So it's necessary to issue an xbmc.sleep() simply to listen for (and process) new events, even if the interval is ridiculously long (eg. 60000). However if you wish to act on an event (such as abort) then the sleep() interval needs to be quite short (sub-second). Bummer.

A queue event model would mean that process threads wouldn't have to keep waking up at regular intervals when there is nothing to do, but clearly this isn't practical right now.