XBMC Python implementation bug?
#1
i spent some nights trying to find a bug in my script, but, after a lot of tests, i'm almost sure it is a bug in xbmc python implementation.

get the following code and save it into a file (e.g. test.py)

Quote:import threading
import xbmcgui

action_previous_menu = 10
pal_16x9 = 7

################################################################################

class myclass(xbmcgui.windowdialog):
def (self):
xbmcgui.windowdialog.(self)

self.setcoordinateresolution(pal_16x9)

self.testbackground = xbmcgui.controlimage(0, 0, 720, 576, "background.png")
self.testbutton = xbmcgui.controlbutton(250, 200, 128, 32, "click me", "button-focus.png", "button-nofocus.png")
self.testlabel1 = xbmcgui.controllabel(250, 250, 200, 20, "")
self.testlabel2 = xbmcgui.controllabel(250, 300, 200, 20, "")

self.addcontrol(self.testbackground)
self.addcontrol(self.testbutton)
self.addcontrol(self.testlabel1)
self.addcontrol(self.testlabel2)

self.setfocus(self.testbutton)

self.mythread = none
self.testcounter = 0

def onaction(self, action):
if action_previous_menu == action:
self.close()

def oncontrol(self, control):
if self.mythread is not none:
self.mythread.stop()
self.mythread = none

self.testcounter = self.testcounter + 1
self.mythread = mythread(self.testlabel1, self.testlabel2, self.testcounter)
self.mythread.start()

################################################################################

class mythread(threading.thread):
def (self, label1, label2, counter):
threading.thread.(self)

self.label1 = label1
self.label2 = label2
self.counter = counter
self.started = threading.event()
self.stopped = threading.event()

def start(self):
self.start()
self.started.wait() # this statement will wait for thread started

def stop(self):
self.stopped.set()
self.join()

def run(self):
self.started.set() # this statement will unlock the function "start"

self.label1.setlabel(str(self.counter))
self.stopped.wait(5)
self.label2.setlabel(str(self.counter))

################################################################################

myclass = myclass()
myclass.domodal()

ok, let's analyze it.
it will simply create a window with a button and two labels.
when you press the button a new thread will be created and started (and the previous one, stopped and destroyed). the thread will fill the first label with a counter value, will wait for at most 5 secs and will fill the second label with the same counter value.
the only "strange" thing is that the mythread.start function will wait for the thread start before going on (look at the self.started.wait() and self.started.set() statements).

now, launch the script and using the remote control press the "select" button and take it pressed. this will cause a quick sequence of mythread.start and mythread.stop.
if you are lucky you will have to wait only few seconds and the counters will stop (if not, continue pressing and it will happen).

as you can notice, the first label will show a value and the second one will show te same value - 1.
this because the self.stopped.wait(5) statement will never exit even if self.stopped.set() has been called and the timeout has elapsed.
moreover, the mythread.stop function (and, obviously, the oncontrol function) will be locked because it will be waiting forever on the self.join() function call.

now the question is: is there a hidden (really hidden Smile) bug in my script or it is a python bug?
Reply
#2
i havent looked at your script but i have also had threading issues with xbmc. the best i could do was to minimize the critical sections of code to two lines.
Reply
#3
the script i posted contains some errors.

line #10 says: def (self):
line #11 says: xbmcgui.windowdialog.(self).
line #46 says: def (self, label1, label2, counter):
line #47 says: threading.thread.(self)

i don't know why, when, with this forum software, you insert the word "<double underscore>init<double underscore>" it is totally deleted.
so, the correct lines are the following.

def <double underscore>init<double underscore>(self):
xbmcgui.windowdialog.<double underscore>init<double underscore>(self)
def <double underscore>init<double underscore>(self, label1, label2, counter):
threading.thread.<double underscore>init<double underscore>(self)

or you can simply download the script clicking here.



Reply
#4
i too have experienced some trouble with threads.
there seems to be some bugs there. things that works perfectly on pc version of python, don't work at all on xbmc.

last changelog i can find about threading:
- 28-10-2005 fixed: possible thread synchronisation problems in python

maby darki has something to say?
or are there more devs that are into python?
Reply
#5
(girotour @ mar. 17 2006,08:59 Wrote:the script i posted contains some errors.
yes this is a known and annoying problem. i recommend replacing underscore with -.

edit: w007! 666 posts. beware the mark of the beast.



Reply
#6
(thor918 @ mar. 17 2006,15:02 Wrote:i too have experienced some trouble with threads.
there seems to be some bugs there. things that works perfectly on pc version of python, don't work at all on xbmc.
hi thor918,
and thank you for your answer.
exactly the same problem, the script runs perfectly on pc, but has problems when running in xbmc. and i use a newer version then 28-10-2005.
it's really driving me mad...



Reply
#7
solved with the new python 2.4.3.
Reply
#8
note about threads:

seems that xbmc hangs it self it you quit the script, and try to shutdown/reboot/etc, [igr works]

i'm aware that there was a little smallbug when the upgrade of python was added, resulting it some wierd errors to do with threads, pretty sure this is fixed now.
** Team XBMC Tester** XBMC 4 ever

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
XBMC Python implementation bug?0