View change properties

I need a function similar to gobject.io_add_watch , but for a variable. For example, you need to check the stop variable, initialized to stop = False , and when stopped, to True it should call the function. I cannot have a separate thread watching a variable in a loop with time.sleep.

Is there such a function or a way to do this?

+6
variables python watch
source share
1 answer

Use property in the class:

 class Stopwatch(object): def __init__(self, callback): self._stop = False self.callback = callback @property def stop(self): return self._stop @stop.setter def stop(self, value): self._stop = value if value: self.callback() 
+17
source share

All Articles