- delete = []
- # run the functions we ought to run
- for tobewoken, idx in zip(self._tobewokens, range(len(self._tobewokens))):
- tobewoken.time_since_call += 1
- if tobewoken.time_since_call >= tobewoken.period:
- tobewoken.f()
- tobewoken.time_since_call = 0
- if tobewoken.one_shot:
- delete.append(idx)
- # delete what we have to delete - in reverse order so the indices stay valid!
- delete.reverse()
- for idx in delete:
- del self._tobewokens[idx]
+ with self._tobewokens_lock:
+ delete = []
+ # run the functions we ought to run
+ for tobewoken, idx in zip(self._tobewokens, range(len(self._tobewokens))):
+ tobewoken.time_since_call += 1
+ if tobewoken.time_since_call >= tobewoken.period:
+ tobewoken.f()
+ tobewoken.time_since_call = 0
+ if tobewoken.one_shot:
+ delete.append(idx)
+ # delete what we have to delete - in reverse order so the indices stay valid!
+ delete.reverse()
+ for idx in delete:
+ del self._tobewokens[idx]