Created
May 29, 2014 19:22
-
-
Save vain/a87026c966e92214744b to your computer and use it in GitHub Desktop.
POC timing with artificial delay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.4 | |
import datetime | |
import time | |
def something(): | |
print(datetime.datetime.now()) | |
# Simulate long running task | |
time.sleep(0.75) | |
start = datetime.datetime.now() | |
if True: | |
start = start.replace(microsecond=0) | |
while True: | |
something() | |
target = start + datetime.timedelta(seconds=1) | |
while target > datetime.datetime.now(): | |
sleep_time = (target - datetime.datetime.now()).total_seconds() | |
time.sleep(sleep_time) | |
start = target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment