[SOLVED] Kodi 15.1 crash on exit when using autoexec.py
#1
HI all,
I'm using Kodi in my store to have a slideshow with my RSS feed always running and every 5 minutes it sholud switch to weather page then back to home.
To archive it I've added my autoexec.py on my .kodi/userdata/ folder with:

Code:
import xbmc, time

xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
time.sleep(10)
xbmc.executebuiltin('XBMC.ActivateWindow(home)')
def slide():
    time.sleep(300)
    xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
    time.sleep(10)
    xbmc.executebuiltin('XBMC.ActivateWindow(home)')
while True:
    slide()


It's working fine even after hours and hours, but when I close it Kodi hangs and even if I kill it the window stay here.

My debug kodi.log: http://xbmclogs.com/psgwxomo8
My debug kodi.old.log: http://xbmclogs.com/pqpkhvxgk

I've tried to run it as a service, with:

- Addon.xml:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.program.divina.setup" name="Divina Setup" version="1.0.0" provider-name="Federico Leoni">
    <requires>
        <import addon="xbmc.python" version="2.14.0"/>
    </requires>
      <extension point="xbmc.service" library="service.py" start="startup" />
      <extension point="xbmc.addon.metadata">
          <platform>all</platform>
          <summary lang="en"></summary>
      </extension>
</addon>

- Service.py:

Code:
import xbmc, time

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    while True:
        if monitor.waitForAbort(10):
            break
        time.sleep(10)
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        time.sleep(10)
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        def slide():
            time.sleep(300)
            xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
            time.sleep(10)
            xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        while True:
            slide()

But is the same.

Code:
18:45:04 T:140672535173056   ERROR: CPythonInvoker(3, /home/effe/.kodi/addons/service.divina.setup/service.py): script didn't stop in 5 seconds - let's kill it

If I remove this customization Kodi works just fine. Please note is not a skin problem because it hangs with every skin I've tried.
Any clue?

Update: Kodi close itself after half an hour. O_o
Reply
#2
You shouldnt use while True but while not xbmc.Monitor().abortRequested(). Also use xbmc.sleep() instead of time.sleep() as u don't need that dependency
Reply
#3
(2015-08-26, 03:06)enen92 Wrote: You shouldnt use while True but while not xbmc.Monitor().abortRequested(). Also use xbmc.sleep() instead of time.sleep() as u don't need that dependency
Then I think you're advising to run it as a service, isn't it?
Code:
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    while not xbmc.Monitor().abortRequested():
        if monitor.waitForAbort(10):
            break
        xbmc.sleep(10)
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        xbmc.sleep(10)
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        def slide():
            xbmc.sleep(300)
            xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
            xbmc.sleep(10)
            xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        while True:
            slide()

Kodi starts to switch to weather very quickly with xbmc.sleep() and it hangs on exit too.
Again, without autoexec.py or service Kodi works fine.
Reply
#4
xbmc.sleep uses miliseconds so it should be xbmc.sleep(10000) for 10 seconds.

It doesn't really matter if running as a service or in autoexec.py. You shouldn't really use while True, that is the bit that is causing kodi to hang on shutdown
Reply
#5
Valeu enen92, obrigado pela informação! Smile

But even using

while not xbmc.Monitor().abortRequested()

in place of BOTH true sentences Kodi hangs:

Code:
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    while not xbmc.Monitor().abortRequested():
        if monitor.waitForAbort(10):
            break
        xbmc.sleep(10000)
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        xbmc.sleep(10000)
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        def slide():
            xbmc.sleep(10000)
            xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
            xbmc.sleep(10000)
            xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        while not xbmc.Monitor().abortRequested():
            slide()

Edit: Ok, now I'm a little confused, even on wiki the examples are using "while true" and the time module...

http://kodi.wiki/view/Service_add-ons

Anyway, the problem is the the second while where the def is called. Without it Kodi didn't hangs but obviously doesn't repeat the script.
Reply
#6
Solved with:

Code:
import xbmc

if __name__ == '__main__':
    monitor = xbmc.Monitor()

    while not xbmc.Monitor().abortRequested():
        if monitor.waitForAbort(10):
            break
        xbmc.sleep(10000)
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        xbmc.sleep(10000)
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        def slide():
            xbmc.sleep(30000)
            xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
            xbmc.sleep(10000)
            xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        while True:
            if monitor.waitForAbort(10):
                break            
            else:
                slide()

a second if did the magic.
Reply
#7
Ah you solved it Smile I would say something similar (however you should really avoid the while true statement). Also I suggest you to always try to reduce the sleep time or at least split it and do some checks in the loop to avoid kodi waiting for a big ammount of time when requested to abort. Something like this:

Code:
import xbmc

monitor = xbmc.Monitor()

def wait(wait_time):
    current_time = 0
    while current_time <= wait_time:
        if not monitor.abortRequested():
            xbmc.sleep(100)
            current_time += 100
        else:
            break
    return
    

def slide():
    aborted_requested = monitor.abortRequested()
    if not aborted_requested:
        wait(10000)    
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
    if not aborted_requested:
        wait(10000)
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
    if not aborted_requested: return True
    else: return False

if __name__ == '__main__':
    while not monitor.abortRequested():
        abort = slide()
        if not abort: break

Some screenshots of your kodi setup on the showcase section of the forum would be great. You know, loads of people usually mistake the use of kodi and it is always cool to see shops and hotels using it Smile

Good luck for your shop

cheers
Reply
#8
Photo 
Thanks for your code snippet way more elegant than mine.

I don't know how is interesting my setup, do you think photos like those will be useful?

http://picpaste.com/IMG_8583-F3IDIoHy.JPG

http://picpaste.com/IMG_8584-pOWy63IM.JPG

Then when I've completed my new py module for Kodi and Odoo I'll share it some more details.
Reply
#9
Yeah, they are great and show people the versatility of kodi and opensource in general. You know, there is that wrong idea for new users that kodi is focused around piracy (or in other words doesn't have any use if not for the addons) and it is always good to see people that find fit for it appart from the usual functionality of media playback.
Your setup looks awesome
Reply
#10
I'll grab a video when I'll finish it and I'll share on hardware showcase forum.
Reply
#11
(2015-08-26, 15:43)enen92 Wrote: Ah you solved it Smile I would say something similar (however you should really avoid the while true statement). Also I suggest you to always try to reduce the sleep time or at least split it and do some checks in the loop to avoid kodi waiting for a big ammount of time when requested to abort. Something like this:
waitForAbort already does that. It'll interrupt and return true on abort request. No need to sleep in stepsWink

(2015-08-26, 15:33)effe Wrote: Solved with:

a second if did the magic.
Actually, it may still hang, if you try to exist during those long sleeps. The best thing to do really, is to avoid using xbmc.sleep and time.sleep altogether and use waitForAbort instead. For example something like this:

Code:
import xbmc

def main():
    monitor = xbmc.Monitor()
    if monitor.waitForAbort(10):
        return

    while True:
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        if monitor.waitForAbort(300):
            break

        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        if monitor.waitForAbort(300):
            break

if __name__ == '__main__':
    main()
Reply
#12
Thanks for the info and correction takoi. I'll see if I can edit the wiki page with more up to date information
Reply
#13
@enen92 and @takoi: +1 for both. Thanks.
Reply

Logout Mark Read Team Forum Stats Members Help
[SOLVED] Kodi 15.1 crash on exit when using autoexec.py0