PDA

View Full Version : help: ram usage problem


Gigi
2009-08-29, 16:31
i wrote this short testing script. it works good and shows this slideshow endlessly.

import xbmcgui, threading, os, time

class test(xbmcgui.WindowDialog):
def __init__(self):
self.pic=xbmcgui.ControlImage(0,0,1200,800,"")
self.addControl(self.pic)
self.restart()

def restart(self):
self.Thread=threading.Thread(group=None,target=sel f.loop,name=None,args=(),kwargs={})
self.Thread.start()

def loop(self):
self.imageNames=[]
for item in os.listdir("/home/gigi/Bilder"):
if item[-4:] == ".jpg" or item[-4:] == ".png":
self.imageNames.append(item)

for i in range(len(self.imageNames)):
self.pic.setImage(os.path.join("special://home", "..", "Bilder", self.imageNames[i]))
time.sleep(5)
self.restart()

mydisplay=test()
mydisplay.doModal()
del mydisplay

the problem with it is that the ram space xbmc uses gets bigger and bigger... endlessly. I'm using ubuntu hardy 8.04.

EDIT: Updated Script Code

jmarshall
2009-08-30, 01:26
The image is probably not being free'd. Check the python interfaces - I think it's in window.cpp, somewhere under xbmc/lib/libPython

Dan Dare
2009-08-30, 13:55
Why not create a single ControlImage and change the image every 5 seconds using ControlImage.setImage()?
See http://xbmc.sourceforge.net/python-docs/xbmcgui.html#ControlImage

Also might be a good idea to use os.path.join and one of the special paths instead of concatenating the paths yourself, as that might not work on anything else but Unixes:


os.path.join("special://home", "Bilder", self.imageNames[i])


See
http://www.xbmc.org/wiki/?title=Special_protocol
http://python.org/doc/2.4/lib/module-os.path.html

Gigi
2009-08-30, 20:56
@jmarshall: I'm sorry but I'm not able to handle with c++. it would be great if you could give me instructions how to solve my problem with c++. (if it's even possible)

@Dan Dare: I tried it with .setImage() but the ram usage problem is the same. thank you for the idea with specialpaths/path.join. see updated script code above.

Dan Dare
2009-08-30, 22:45
Is it just me or are you starting too many threads? To me it looks like its going __init__ > restart() > new thread > loop > restart > new thread > etc...

If you want the slideshow to run indefinite, why not wrap the the for() with a while (True) loop?

Btw, why are you using threads? Is it because you plan to add some Cancel button to stop the slideshow or something like that?

Gigi
2009-09-01, 11:28
yeah you're right. one thread would be enough. this slideshow will be just a small part of a screen design. it must be manageable by an other module, so I need threading to start and stop several modules at the same time.

Dan Dare
2009-09-01, 20:58
Good job - keep a hold of them threads or they're going to crash very quickly on Xboxes :-)