I've searched around but didn't find anything like this. Let's say I have an army of threads, that keep reading and updating an integer variable x. I would like a callback for when x changes over a certain margin, let's say 500, to run the callback.
How can this be done without putting a heavy load on the system, like having a thread that has a while true and checks if the variable has changed? Performance is critical. But so are ethics.
In plain code would be something like this:
x = 10
def runMe():
print('Its greater than 500!!')
def whenToRun():
return x >= 500
triggers.event(runMe, whenToRun)
xhave to be a global variable, or it can be, say, an attribute of some object?xwill be an attribute of some object__setitem__-hooked container as a module dict, either in a hacky way, or with a nice import hook that gives all.pyfiles your custom dict subclass. Maybe other ways as well.