Threading and HOME.setProperty changes?
#1
The below worked fine on Leia, threading ran in background updating property and was reflected in Kodi live changing VAR colors (script.colorbox).

Now in Matrix, you only see the last color change after X amount of time (time being steps x sleep), Kodi runs as normal no freezes, but does not show the colors changing between steps (first color *sleep delay* last color). So threading is running, but property isn't getting changed until the sub returns, whereas before sub runs in background changing property no problems.

Cannot see what you have changed (security? xbmc.sleep (although this works fine in other non threaded subs))?

thanks!
Code:
from threading import Thread
HOME =              xbmcgui.Window(10000)

...
    tmc = Thread(target=linear_gradient, args=(cname, HOME.getProperty(var3)[2:8], imagecolor[2:8], lgsteps, lgint, var3))
    tmc.start()

...
def linear_gradient(cname, start_hex="000000", finish_hex="FFFFFF", n=10, sleep=50, s_thread_check=""):
    if start_hex == '' or finish_hex == '':
        return
    s = hex_to_RGB('#' + start_hex)
    f = hex_to_RGB('#' + finish_hex)
    RGB_list = [s]
    for t in range(1, n):
        if HOME.getProperty(s_thread_check)[2:8] != start_hex:
            return
        curr_vector = [
            int(s[j] + (float(t)//(n-1))*(f[j]-s[j]))
            for j in range(3)
        ]
        HOME.setProperty(cname, RGB_to_hex(curr_vector))
        xbmc.sleep(sleep)
    return
Reply
#2
What is HOME?
Reply
#3
Sorry! Long time since I touched a python! Smile

I've added HOME. above.
Code:
HOME =              xbmcgui.Window(10000)

The default.py calls the utils.py (utils.py is threading), seems the utils.py can now not set HOME.property, as when it returns control to default.py, the HOME.property gets set there again before returning back to kodi.
But all this worked fine in Leia..
Reply
#4
Can you try time.sleep instead of xbmc.sleep?
Reply
#5
Tried, doesn't like it, script doesnt error but freezes thread it seems. When shutting down this error (using time.sleep):
Code:
2021-06-18 09:02:09.879 T:13628    INFO <general>: CPythonInvoker(3, C:\Users\dan\AppData\Roaming\Kodi\addons\script.colorbox\default.py): script successfully run
2021-06-18 09:02:09.879 T:13628    INFO <general>: CPythonInvoker(3, C:\Users\dan\AppData\Roaming\Kodi\addons\script.colorbox\default.py): waiting on thread 13052
2021-06-18 09:02:14.893 T:7976    ERROR <general>: CPythonInvoker(3, C:\Users\dan\AppData\Roaming\Kodi\addons\script.colorbox\default.py): script didn't stop in 5 seconds - let's kill it
2021-06-18 09:02:14.914 T:7976     INFO <general>: Application stopped
2021-06-18 09:02:15.115 T:7976     INFO <general>: XBApplicationEx: destroying...

If I change 'HOME.setProperty(cname, RGB_to_hex(curr_vector))' to an actual skin var name like 'HOME.setProperty("ImageColorFIVE", RGB_to_hex(curr_vector))', then I can see the thread is running and changing the property as it flickers the color (but is erroring to default white). So it is running and updating property but not how it should... Grrrr, sorry not more descriptive, brain out of practice!
Reply
#6
Also the thread is called by a thread (utils.Color_Only), but this was all fine, this default.py calling sub:
Code:
            if not FIVE_daemon_set == '':
                self.image_now_FIVE = xbmc.getInfoLabel("Control.GetLabel(7975)")
                if (self.image_now_FIVE != self.image_prev_FIVE and self.image_now_FIVE != "") or HOME.getProperty("FIVE_daemon_fire"):
                    HOME.setProperty('Daemon_FIVE_ImageUpdating', self.image_now_FIVE)
                    HOME.clearProperty("FIVE_daemon_fire")
                    #HOME.clearProperty("ImageFilterFIVE")
                    try:
                        HOME.setProperty('ImageFilterFIVE', utils.ColorBox_go_map(self.image_now_FIVE, FIVE_daemon_set))
                    except Exception as e:
                        utils.log("5err: %s img: %s" % (e,self.image_now_FIVE))
                    else:
                        self.image_prev_FIVE = self.image_now_FIVE
                        HOME.setProperty("OldImageColorFIVE", HOME.getProperty("ImageColorFIVE"))
                        HOME.setProperty("OldImageCColorFIVE", HOME.getProperty("ImageCColorFIVE"))
                        HOME.setProperty('ImageFIVE', self.image_now_FIVE)
                        tm1 = Thread(target=utils.Color_Only, args=(self.image_now_FIVE, "ImageColorFIVE", "ImageCColorFIVE"))
                        tm1.start()
                    HOME.setProperty('Daemon_FIVE_ImageUpdating', '')
            cfa_daemon_set = HOME.getProperty("cfa_daemon_set")
Reply
#7
Ok, the property is updating, seems something is borked with the RGB to HEX loop or vice versa, I can change colors in thread by setting it to the color of the thread loop number, and it works (all be it the same color for everything, heh.).,
 
Code:
    def RGB_to_hex(RGB):
    RGB = [int(x) for x in RGB]
    return "FF"+"".join(["0{0:x}".format(v) if v < 16 else "{0:x}".format(v) for v in RGB])

This seems to be the problem.. Python 3 implement different??

edit: nope, not it. following code doesnt change result 'return 'FF{:02x}{:02x}{:02x}'.format(RGB[0], RGB[1] , RGB[2])'

something to do with curr_vector [...]
Doesn't keep up with thread, or in thread gets lost HuhHuhHuh


Repo page here:
https://github.com/BADMS/script.colorbox...b/Utils.py
Reply
#8
FIXED. Python 3 Floor Division changed..
Code:
curr_vector = [
            int(s[j] + (float(t)//(n-1))*(f[j]-s[j]))
            for j in range(3)
        ]

to

Code:
curr_vector = [
            int(s[j] + (float(t)/(n-1))*(f[j]-s[j]))
            for j in range(3)
        ]

Just use normal division until I work out why or what etc.
Reply



Logout Mark Read Team Forum Stats Members Help
Threading and HOME.setProperty changes?0
This forum uses Lukasz Tkacz MyBB addons.