Sleep for a given interval with respect to the start timestamp. So, if the start timestamp is 1337 and nseconds is 10, the method will actually sleep for nseconds - (current_timestamp - start_timestamp). So if the current timestamp is 1340, we'll only sleep for 7 se
(self, start_ts, nseconds)
| 45 | pass |
| 46 | |
| 47 | def sleep_for_interval(self, start_ts, nseconds): |
| 48 | """ |
| 49 | Sleep for a given interval with respect to the start timestamp. |
| 50 | |
| 51 | So, if the start timestamp is 1337 and nseconds is 10, the method will |
| 52 | actually sleep for nseconds - (current_timestamp - start_timestamp). So |
| 53 | if the current timestamp is 1340, we'll only sleep for 7 seconds (the |
| 54 | goal being to sleep until 1347, or 1337 + 10). |
| 55 | """ |
| 56 | sleep_time = nseconds - (time.monotonic() - start_ts) |
| 57 | if sleep_time <= 0: |
| 58 | return |
| 59 | self._logger.debug('Sleeping for %s', sleep_time) |
| 60 | # Recompute time to sleep to improve accuracy in case the process was |
| 61 | # pre-empted by the kernel while logging. |
| 62 | sleep_time = nseconds - (time.monotonic() - start_ts) |
| 63 | if sleep_time > 0: |
| 64 | time.sleep(sleep_time) |
| 65 | |
| 66 | def loop(self, now=None): |
| 67 | """ |