Runs all function that have been registered as callbacks. Functions can return False (or 0) if they should not be called any more. If there are no callbacks, the timer is automatically stopped.
(self)
| 1156 | """Used to set single shot on underlying timer object.""" |
| 1157 | |
| 1158 | def _on_timer(self): |
| 1159 | """ |
| 1160 | Runs all function that have been registered as callbacks. Functions |
| 1161 | can return False (or 0) if they should not be called any more. If there |
| 1162 | are no callbacks, the timer is automatically stopped. |
| 1163 | """ |
| 1164 | for func, args, kwargs in self.callbacks: |
| 1165 | ret = func(*args, **kwargs) |
| 1166 | # docstring above explains why we use `if ret == 0` here, |
| 1167 | # instead of `if not ret`. |
| 1168 | # This will also catch `ret == False` as `False == 0` |
| 1169 | # but does not annoy the linters |
| 1170 | # https://docs.python.org/3/library/stdtypes.html#boolean-values |
| 1171 | if ret == 0: |
| 1172 | self.callbacks.remove((func, args, kwargs)) |
| 1173 | |
| 1174 | if len(self.callbacks) == 0: |
| 1175 | self.stop() |
| 1176 | |
| 1177 | |
| 1178 | class Event: |