| 481 | return looper |
| 482 | |
| 483 | def run(self): |
| 484 | with self._coord.stop_on_exception(): |
| 485 | self.start_loop() |
| 486 | if self._timer_interval_secs is None: |
| 487 | # Call back-to-back. |
| 488 | while not self._coord.should_stop(): |
| 489 | self.run_loop() |
| 490 | else: |
| 491 | # Next time at which to call run_loop(), starts as 'now'. |
| 492 | next_timer_time = time.time() |
| 493 | while not self._coord.wait_for_stop(next_timer_time - time.time()): |
| 494 | next_timer_time += self._timer_interval_secs |
| 495 | self.run_loop() |
| 496 | self.stop_loop() |
| 497 | |
| 498 | def start_loop(self): |
| 499 | """Called when the thread starts.""" |