XBMC Python implementation bug

January 6th, 2009
  • i already posted this message in python scripts development section, but i think this section is more appropriate because it seems to be a bug in xbmc python implementation (obviously i'm working with the latest cvs code available).
    i also posted it on sourgeforge (request id 1451830).

    get the following code and save it into a file (e.g. test.py) or download it from here (https://sourceforge.net/tracker/download.php?group_id=87054&atid=581838&file_id=171288&aid=1451830).

    import threading
    import xbmcgui

    action_previous_menu = 10
    pal_16x9 = 7

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

    class myclass(xbmcgui.windowdialog):
    def --init--(self): # substitute '--' with double underscore
    xbmcgui.windowdialog.--init--(self) # substitute '--' with double underscore

    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 --init--(self, label1, label2, counter): # substitute '--' with double underscore
    threading.thread.--init--(self) # substitute '--' with double underscore

    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).
    now the python environment is locked somewhere and, also pressing buttons while you're blue in the face, you won't be able to receive any event or to stop the script.

    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.


  • solved with the new python 2.4.3.


  • still no response at https://sourceforge.net/tracker....=581838 (https://sourceforge.net/tracker/index.php?func=detail&aid=1451830&group_id=87054&atid=581838)

    they are probably busy patching up the new version.


  • another quetion,when run scripts(whatever one) with new version 2.4.3,in log file,it records that "error: emulated function dll_fstat failed".
    what does this log means?does anything wrong with the new python version?


  • still no response at https://sourceforge.net/tracker....=581838 (https://sourceforge.net/tracker/index.php?func=detail&aid=1451830&group_id=87054&atid=581838)

    they are probably busy patching up the new version.
    yes, i've noticed that the bug has not been assigned to anyone.
    let's hope in the future...


  • nothing wrong, will do a new commit soon to remove those incorrect messages.


  • is this also the reason that my scripts sometimes quit loading. i have to reboot to succeed.

    sollie







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about XBMC Python implementation bug , Please add it free.