Nested condition variables are fun!
That release and acquire surrounding the wait are how you allow one of the timelines to start slipping relative to the other one.
def current_updates(self):
with self.app.cond:
self.app.cond.wait_for(
lambda: self.app.positions_ready
)
while 1:
if not self.app.isConnected():
self.stop()
if not self.running:
break
with self.cond:
# Skip all position updates while dead-reckoning
if self.dead_reckoning:
self.app.cond.release()
self.cond.wait_for(lambda: not self.dead_reckoning)
self.app.cond.acquire()
current = self.app.positions.copy()
if self.current != current:
self.current = current
self.cond.notify_all()
self.app.cond.wait(timeout=2)