Skip to content

Instantly share code, notes, and snippets.

@vain
Created May 29, 2014 19:22
Show Gist options
  • Save vain/a87026c966e92214744b to your computer and use it in GitHub Desktop.
Save vain/a87026c966e92214744b to your computer and use it in GitHub Desktop.
POC timing with artificial delay
#!/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