• 1(current)
  • 2
  • 3
  • 4
  • 5
  • 10
Python Inside
#1
i noticed that a ported version of python is included in the xbmc source. this is great as python is a simple and powerful object oriented scripting language. so how is python used by xbmc? are scripts used as a part of the application or is the intent only to execute external utility scripts?

the ability to tweak scripts and see the results without recompiling and downloading to the xbox would sure be nice...
#2
you can select the scripts like a program or movie and start it. Smile

too bad that i have no idea of python.
read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
#3
i'm really wondering the same thing. i've looked through the forums and docs on the xbmp site, and i couldn't find a definite answer.

does xbmc have a full embedded python interpreter, or is it a limited set of functionality? is there socket support? like, would i be able to build a web service / client in python?
#4
Quote:does xbmc have a full embedded python interpreter, or is it a limited set of functionality?
full

Quote:is there socket support?
yes

Quote: like, would i be able to build a web service / client in python?
yes



read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
#5
can any of the devs give a bit more info on this? as it sounds very interesting.
how do the scripts interact with xbmc? how exactly do you execute scripts? i tried selecting a small test script in xbmc, but it didn't seem to have any effect.
#6
first of all 'python 2.3' is embedded into xbmc and you the need to do the following to get it working

extract the directories from python.rar (cvs\xbmc\python\python.rar)
to "xbmc home dir\python\"
and if you want some examples you should extract scripts.rar(cvs\xbmc\scripts\scripts.rar)
to "xbmc home dir\scripts\"

you will now have the next directory structure in xbmc
xbmc
  python
      lib
      temp
      www
  scripts
      medusa

you execute scripts thrue the myscripts gui which is under settings->scripts.
currently there is no interaction with xbmc, for example you can't see any output from the python interpreter (this will be added because it's the only way to see where the script stops when an error occours)

included in scripts.rar are the next files
Quote:chat-server.py: runs a chat server on port 4000
download_apleasure_zip.py: downloads a file from ftp and places it in your xbmc home dir
download_xskit303_exe.py: downloads another file from ftp
echo_server_port_50007.py: runs an echo server on port 50007
mp3.py: only used for testing and doesn't work
url_fetcher_asyncore.py: used for testing and doesn't work
weather.py: used for testing and doesn't work

medusa\start_medusa: runs an ftp / web and chat server on the ports 8021, 8080 and 8888
if you need any documentation or need more scripts examples you can try the official python website http://www.python.org
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
#7
Question 
darkie, as the coder of xbmc's python interpreter can you tell us all a little more about the techical aspects behind it, things like; is it loaded into a pragma section?, is it or will it be loaded by default?, how much ram does it use?, once the python interpreter is loaded into memory will/can it be unloaded when not used anymore or is reboot nessesary?, once a python script is loaded into memory will/can it be unloaded when not running anymore?, where are you planning to take this development wise?, and how do you plan to implement it in the gui, now & later?

...and other things like that, tia Image
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
#8
a dream becomes to be a reality!!
yes, yes. i want develop some webservice, so dear python dev implementator tell us anything is possibile about this wonderful part Smile

it's clear that i'm excited? :d
windragz
it difficult to break 2048 bit as try to find a sock at morning, it's just matter of time.
#9
>is it loaded into a pragma section?
yes it is

>is it or will it be loaded by default?
no

>how much ram does it use?
when loaded about 350kbyte

> once the python interpreter is loaded into memory will/can it be unloaded when not used anymore
no, sorry?,

>once a python script is loaded into memory will/can it be unloaded when not running anymore?
yes
frodo
XBMC Project Founder (Retired), now head programmer of MediaPortal
#10
Sad 
(frodo @ oct. 11 2003,09:46 Wrote:> once the python interpreter is loaded into memory will/can it be unloaded when not used anymore
no, sorry?
why? i mean it must be possible somehow, or isn't? this will be a challange for all you devs to figure out Image
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
#11
why?

cause darkie couldnt get it to work (yet)
hopefully he'll manage to fix it

frodo
XBMC Project Founder (Retired), now head programmer of MediaPortal
#12
(frodo @ oct. 11 2003,14:13 Wrote:why? cause darkie couldnt get it to work (yet)
hehe, i meant the technical reason. i already knew that it didn't, i just thought i start an open dev/code discussion here Image
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
#13
k here's why:

python is using lots of static functions & vars
the problem is that static functions & vars dont work with section loading. we didnt find a solution to this yet
there's one solution and thats 2 rewrite python so it doesnt use any static things anymore. but thats a lot of work
so if any compiler/xdk/c++ guru's know a way how to get section loading 2 work with static vars & functions please let us know
frodo
XBMC Project Founder (Retired), now head programmer of MediaPortal
#14
k, first of all, python is made for working in processes and not threads, that means if you run a program in windows and stop it, all used memory is given back to the operating system.
since the xbox doesn't work with processes used memory that isn't released by python won't be given back to the xbox.

python is managing memory in a special way. it doesn't allocate memory for every object or string that is created, but instead it allocates 256k(called an area) of memory at once and keeps track of all objects, strings that are placed in it.
once you don't need an object anymore, python removes it from the 256k area but doesn't give the memory back to the system, instead when a new object is created, this object is placed in that free part of the area. python does this because it is faster then allocating / deallocating memory.
when more then 256k of memory is needed another area of 256k is created and so on.
all these area's are only released when a proces ends, and there is the problem on the xbox. memory once needed for a script in python is never given back to xbmc.

python as it exists in xbmc is created with 2 pragma section: python and py_rw.
python is a section which contains  c / c++ code and memory that can't change, this section is about 800k.
py_rw contains variable memory that is modified when python is used, this section is about 300k.

at startup of xbmc none of these sections are loaded, python doesn't use any memory at all.

when a python script is selected in xbmc to execute. both python and py_rw are loaded into memory and python is initialized. at this moment 1200k of memory is used.
now the script is beeing executed and if it needs memory for storing stuff a new area (see above) is created.
that means that if a script uses 4 areas, a total of 4 * 256k + 1200k = 2200k of memory is used from the 64mb available on the xbox.

when the script ends, all 4 areas are cleaned so they can be used when an user selects a next script to execute( 4 * 256k of memory isn't given back to the xbox!Wink.
section python will be unloaded by xbmc and py_rw is not unloaded.
at this moment, 1 mb for the areas and 300k for py_rw is in use by python.
if we select another script to run, section python is loaded again. if this scripts would need 750k of memory, python will use the existing areas for it. that means 2200k of memory is used

i didn't unload py_rw because loading it again will reset all memory. if we would unload py_rw and load it when we would need python again. python would think there where no areas created before and therefore creates new areas.
at this moment the 1 mb of areas created for the first script is lost and will never be used again (a memory leak of 1 mb!Wink

that was the technical part, so what can you expect to come.
well there are still some small bugs to fix (including 256k areas that are never given back to xbmc).
currently i am buzy to integrate some xbmc stuff into xbmc, like a yes / no dialog and the progress dialog. for example, you could use the progress dialog when downloading a file from ftp so an user could see how long it takes before it would finish.

darkie
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
#15
(darkie @ oct. 13 2003,15:43 Wrote:currently i am buzy to integrate some xbmc stuff into xbmc, like a yes / no dialog and the progress dialog. for example, you could use the progress dialog when downloading a file from ftp so an user could see how long it takes before it would finish.
sounds good.
i was thinking about writing some python scripts to control a tivo over the network. just simple tasks such as deleting shows, etc. to complement duo's work on streaming video from tivo. i don't think it should be too difficult.
i would need python to be able to display a list of objects (in the same format as it displays a list of videos or mp3s would be great) in xbmc and then wait for the user to select one and pass the selected option on to the script. is that functionality likely to be available to python?
  • 1(current)
  • 2
  • 3
  • 4
  • 5
  • 10

Logout Mark Read Team Forum Stats Members Help
Python Inside0