Solved python executebuiltin code blocking
#1
Information 
I'm not sure if I'm just miss understanding this or if its a bug. I have a python addon that runs another python script using
xbmc.executebuiltin('XBMC.RunScript(\Scripts\myscript.py)', True)
from what I read here
http://kodi.wiki/view/Built-in_scripting...rom_python
It should wait for that script to complete before continuing but it does not. Now am I miss understanding what code blocking is or is this a bug?
I'm very new to python so sorry if this is a dumb question.
Reply
#2
As far as I understand, for scripts launched via "RunScript" built-in a new Python interpreter is spawned. So this is a feature.
If you need to wait for some task to finish, then, I think, you need to use a normal function call.
Reply
#3
It means wait until it starts, not till it completes.

This wiki page is very old. If you are creating an addon then avoid using RunScript in the first place
Reply
#4
That makes sense. What do you guys suggest i do. I run another script in the middle of my main and wait for it to complete. I originally used subprocess but it needed to be in the same name space to import xbmc python models. I got around this by using the above and having the second script write a file before exiting. I placed a loop in the main checking for that file. This works but im just wondering if there is a more pythonic way to accomplish this? Just asking for my own education. Thanks
Reply
#5
You could use a skin property to tell the first script the second one is done. It's functionally not any different than your file idea, but it uses all internal stuff so you don't have to worry about the file not getting written properly. In the first script you would set something like this just before you call the second one:

Code:
xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning", "True")

Then call the second script and put the following loop right below the call to the second script:

while (xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty("MyScript.ExternalRunning") == "True"):
time.sleep(1)
[/code]

The first script will run through that loop until the second one sets the skin property to something different. You would do that in the second script this way:

Code:
xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning", "False")

It's a little messy, but something similar to this works for another addon I have. In that case I have a mini-API that others can use, but their script can't exit until mine does.
Reply
#6
Communication between processes is a popular topic.

KenV99 has created this module that might be of interest: http://forum.kodi.tv/showthread.php?tid=209171

But my question is, why don't you change the script so that it can be imported as a module?

Post the script and I could help with the specifics.
Reply
#7
(2014-11-28, 06:17)pkscout Wrote: You could use a skin property to tell the first script the second one is done. It's functionally not any different than your file idea, but it uses all internal stuff so you don't have to worry about the file not getting written properly. In the first script you would set something like this just before you call the second one:

Code:
xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning", "True")

Then call the second script and put the following loop right below the call to the second script:

while (xbmcgui.Window(xbmcgui.getCurrentWindowId()).getProperty("MyScript.ExternalRunning") == "True"):
time.sleep(1)
[/code]

The first script will run through that loop until the second one sets the skin property to something different. You would do that in the second script this way:

Code:
xbmcgui.Window(xbmcgui.getCurrentWindowId()).setProperty("MyScript.ExternalRunning", "False")

It's a little messy, but something similar to this works for another addon I have. In that case I have a mini-API that others can use, but their script can't exit until mine does.
Didn't know about this. I think I can use it on several things I've been trying to solve. Thanks so much for showing me!
Reply
#8
(2014-11-28, 06:33)Karnagious Wrote: Communication between processes is a popular topic.

KenV99 has created this module that might be of interest: http://forum.kodi.tv/showthread.php?tid=209171

But my question is, why don't you change the script so that it can be imported as a module?

Post the script and I could help with the specifics.

If you want to take a look the addon is called audo
https://github.com/lsellens/xbmc.addons
it has 4 parts to it. The two scripts I'm referring to are in script.service.audo the service.py needs to wait for resources/audo.py to complete. It was written for openelec but should run on any linux based xbmc/kodi install.Any feed back you have is very appreciated.
Reply
#9
I dont see why you couldnt put that entire script into a function and import it.
Reply
#10
(2014-11-28, 22:13)otkaz Wrote:
(2014-11-28, 06:33)Karnagious Wrote: Communication between processes is a popular topic.

KenV99 has created this module that might be of interest: http://forum.kodi.tv/showthread.php?tid=209171

But my question is, why don't you change the script so that it can be imported as a module?

Post the script and I could help with the specifics.

If you want to take a look the addon is called audo
https://github.com/lsellens/xbmc.addons
it has 4 parts to it. The two scripts I'm referring to are in script.service.audo the service.py needs to wait for resources/audo.py to complete. It was written for openelec but should run on any linux based xbmc/kodi install.Any feed back you have is very appreciated.
This is python programming 101. You clearly already know how to create functions so im sure why you don't. 1: define a function named 'main' in audo.py and move everything in audo.py into it. 2: in service.py do import audo; audo.main()
Stay far away from the ugly window property hacks. You should also not need to use Runscript to call your own addon. Runscript is for running external addons/scripts.
Reply
#11
(2014-11-30, 18:32)takoi Wrote:
(2014-11-28, 22:13)otkaz Wrote:
(2014-11-28, 06:33)Karnagious Wrote: Communication between processes is a popular topic.

KenV99 has created this module that might be of interest: http://forum.kodi.tv/showthread.php?tid=209171

But my question is, why don't you change the script so that it can be imported as a module?

Post the script and I could help with the specifics.

If you want to take a look the addon is called audo
https://github.com/lsellens/xbmc.addons
it has 4 parts to it. The two scripts I'm referring to are in script.service.audo the service.py needs to wait for resources/audo.py to complete. It was written for openelec but should run on any linux based xbmc/kodi install.Any feed back you have is very appreciated.
This is python programming 101. You clearly already know how to create functions so im sure why you don't. 1: define a function named 'main' in audo.py and move everything in audo.py into it. 2: in service.py do import audo; audo.main()
Stay far away from the ugly window property hacks. You should also not need to use Runscript to call your own addon. Runscript is for running external addons/scripts.
Thanks I need a 101. I learned what I have from looking at other peoples code, reading pieces of tutorials, and a lot of trial and error. Really need to sit down and read a full python tutorial one of these days...
Reply

Logout Mark Read Team Forum Stats Members Help
python executebuiltin code blocking0