Solved import xbmcaddon in subprocess
#1
Hi, I'm not the most knowledgeable about threading in python to start with. I'm working on an addon that launches some subprocesses using subprocess.call. In the script I'm running with subprocess I would like to be able to import some xbmc modules such as xbmcaddon. From my understanding these modules are only available to xbmc itself. Is there anyway around this? Could I run the subprocesses differently and have it available? The addon I'm working on is a service and in my main service.py I'm importing xbmc python modules and using them just fine. It's only in its subprocess scripts where I'm running into a brick wall. Thanks in advance for any advice.
Reply
#2
If you need to run your separate Python script within XBMC namespace then you can use:
PHP Code:
xbmc.executebuiltin('RunScript(<full_path_to_the_script>,<comma_separated_arguments>'
Reply
#3
You're calling a python script with subprocesses from python? You're probably looking for threads. I have no idea why anyone would need processes for this...
Reply
#4
I'm no threading expert, but I have an XBMC Addon that spawns a new thread to do stuff. They way it's setup, the operations in the spawned thread still have access to all the XBMC stuff as well as objects inside the script.

https://github.com/pkscout/script.speedfaninfo
Reply
#5
(2014-04-11, 10:26)Roman_V_M Wrote: If you need to run your separate Python script within XBMC namespace then you can use:
PHP Code:
xbmc.executebuiltin('RunScript(<full_path_to_the_script>,<comma_separated_arguments>'
Thanks for all the suggestions. I tried to use xbmcs executebuild in but im getting nothing. no error and the script never runs

Code:
try:
    xbmc.executebuiltin('XBMC.RunScript(__start__)', True)
except Exception, e:
    xbmc.log(e, level=xbmc.LOGERROR)
doesnt even log an exception
Code:
subprocess.call(['python', __start__])
This works but I don't have access to the xbmc python modules.
I do want my service.py to halt untill the script I'm executing finishes. Any idea why executebuilt in could be failing with no error?
Reply
#6
Is "__start__" a variable? It appears so. It's being used as a variable in your subprocess.call line, but as a literal string in the executebuiltin line.

Maybe:
Code:
try:
    xbmc.executebuiltin('XBMC.RunScript(%s, True)' % (__start__))
except Exception, e:
    xbmc.log(e, level=xbmc.LOGERROR)
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#7
(2014-04-14, 21:21)otkaz Wrote:
(2014-04-11, 10:26)Roman_V_M Wrote: If you need to run your separate Python script within XBMC namespace then you can use:
PHP Code:
xbmc.executebuiltin('RunScript(<full_path_to_the_script>,<comma_separated_arguments>'
Thanks for all the suggestions. I tried to use xbmcs executebuild in but im getting nothing. no error and the script never runs

Code:
try:
    xbmc.executebuiltin('XBMC.RunScript(__start__)', True)
except Exception, e:
    xbmc.log(e, level=xbmc.LOGERROR)
doesnt even log an exception
Code:
subprocess.call(['python', __start__])
This works but I don't have access to the xbmc python modules.
I do want my service.py to halt untill the script I'm executing finishes. Any idea why executebuilt in could be failing with no error?

Obviously you do not observe xbmc.executebuiltin call signature as shown in my example. xbmc.executebuiltin takes exactly 1 string argument, and a built-in function with all its arguments must be represented as a single string literal/variable.
Reply
#8
(2014-04-15, 08:14)Roman_V_M Wrote:
(2014-04-14, 21:21)otkaz Wrote:
(2014-04-11, 10:26)Roman_V_M Wrote: If you need to run your separate Python script within XBMC namespace then you can use:
PHP Code:
xbmc.executebuiltin('RunScript(<full_path_to_the_script>,<comma_separated_arguments>'
Thanks for all the suggestions. I tried to use xbmcs executebuild in but im getting nothing. no error and the script never runs

Code:
try:
    xbmc.executebuiltin('XBMC.RunScript(__start__)', True)
except Exception, e:
    xbmc.log(e, level=xbmc.LOGERROR)
doesnt even log an exception
Code:
subprocess.call(['python', __start__])
This works but I don't have access to the xbmc python modules.
I do want my service.py to halt untill the script I'm executing finishes. Any idea why executebuilt in could be failing with no error?

Obviously you do not observe xbmc.executebuiltin call signature as shown in my example. xbmc.executebuiltin takes exactly 1 string argument, and a built-in function with all its arguments must be represented as a single string literal/variable.
Thanks for the reply, I changed it to a string and everything is working now. Thank you for all your help.
Reply

Logout Mark Read Team Forum Stats Members Help
import xbmcaddon in subprocess0