Kodi Community Forum

Full Version: Prevent script from running twice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
the python script I am trying to write takes a fair bit of time to finish. While the script is running I don't want the user to be able to start the script again because the DialogProgressBG acts weird and it wouldn't make any sense to run twice.

I thought about some lock property in the settings which will be set on start but this wouldn't work in cases where the script or even Kodi itself crashes.

Can you tell me the proper way to solve this? Is there any way I can modify the addon.xml or something so Kodi won't allow it?
Oh my god and this thread isn't even 10 days old, I am so sorry! Sad

But thank you very much for linking it, this is exactly what I wanted to know!
I just tried it but unfortunately ran into problems.
I created a mini script which just sleeps 5 seconds, the code is here:
Code:
import xbmc, xbmcgui, time

WIN = xbmcgui.Window(10000)
if not WIN.getProperty('my_addon.running'):
    WIN.setProperty('my_addon.running', 'True')
    xbmc.log('Start doing stuff')
    sleep_here
    xbmc.log('Finished doing stuff')
    WIN.clearProperty('my_addon.running')
For some reason the sleep part gets blocked in this forum so here is the correct version: http://pastebin.com/KiBNYie2

When I run this script three times in the 5 second time frame (pressing 3 times enter) the main code block will be executed twice (the second time starts exactly when the first stops).
If I increase the sleep timer I also get an error that the script does not respond:
Quote:ERROR: CPythonInvoker(...): script didn't stop in 5 seconds - let's kill it
I found this here:
Quote:I know that when an addon is started form the Addons Window, only a single Instance of an Addon can run(XBMC closes any that may be running in the background).
http://forum.kodi.tv/showthread.php?tid=97353

So I just have to check xbmc.abortRequested regularly and clean everything up if that happens.

Problem is solved now, thanks Smile