Python Interpreter Development "Python Inside"
#1
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
Reply
#2
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.
Reply
#3
>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
Reply
#4
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.
Reply
#5
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
Reply
#6
(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.
Reply
#7
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
Reply
#8
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
Reply
#9
darkie, thx for the explanation.
i still think python in xbmc has a lot of potential
especially when its able to access xbmc stuff like dialogs,windows etc.
things i would like 2 see for python:

1. bind a button control to a script.
so pressing a button will run a script
2. python scripts should b able to use the controls like:
- cguiimage to display an image
- list control
- text area
- button
- spincontrol

3. mapping of keys -> python

with these 3 things one should b able to build almost anything in pyton

frodo
XBMC Project Founder (Retired), now head programmer of MediaPortal
Reply
#10
ok, made a little progress.
with python now, you can use the 4 dialogs (dialogok, dialogyesno, dialogselect, and dialogprogress)

Quote:1. bind a button control to a script.
so pressing a button will run a script
2. python scripts should b able to use the controls like:
- cguiimage to display an image
- list control
- text area
- button
- spincontrol

3. mapping of keys -> python
1 and 2 are both possible, but what exactly do you mean with 3. mapping of keys -> python?
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
Reply
#11
for xbmc there is no documentation atm. but since writing python code for windows is the same as writing it on the xbox you should be able to find most information at python.org

for xbmc specific functions you can take a look at the examples which are in cvs\scripts\

problem for now is that there isn't any error output to xbmc, so you can't see if the script runs ok or not.
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
Reply
#12
ok, python has the option now to create windows where text and images can be drawn on.
i've just added a small example to the cvs tree so people can have a look at it.

note, it is impossible to close a window at this time with your controller or remote. will be fixed soon.
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
Reply
#13
just did another update to python.

actions are now send to a window created with python. this means that when you press back on your remote control, the script will recieve action_previous_menu which is defined in keymap.xml.

i have updated windowexample.py to give you some idea.
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
Reply
#14
hi

does the pil library is planned to be added in your port darkie?
it's useful to process images.
more infos here : pil website

i don't know at all how python libraries are working, and also i have no ideas how to compile them for xbmc. so more infos about this process could help us all i guess.

thanks

alex
Reply
#15
Quote:does the pil library is planned to be added in your port darkie?
maybe, but not at this time. problem is al those libraries take a lot of memory and python is already using to much

about the w.domodal().
if you leave it away, you will see that the python window doesn't stay onscreen because the python script just ends. using w.domodal() or an endless loop will let the script run forever. with the difference that

w.domodal() takes no processor speed and stops when w.close() is called.

an endless loop will take 100 % processor speed and only stops when you break out of the loop

and i'll try to upload new sources to cvs today which makes it possible to use xbmc playlists and add buttons to the window
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
Reply

Logout Mark Read Team Forum Stats Members Help
Python Interpreter Development "Python Inside"0