2006-03-17, 02:41
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)
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 ) bug in my script or it is a python bug?
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 ) bug in my script or it is a python bug?