Skip to content

Instantly share code, notes, and snippets.

@jacekmigacz
Created May 28, 2018 06:41
Show Gist options
  • Save jacekmigacz/56a2ed4760284a1f785c78f9d3fe3ebd to your computer and use it in GitHub Desktop.
Save jacekmigacz/56a2ed4760284a1f785c78f9d3fe3ebd to your computer and use it in GitHub Desktop.
import time
def busy_sleep(secs):
sts, lts = time.perf_counter(), time.perf_counter()
mf = 0
while True:
nts = time.perf_counter()
dt = nts - sts
if dt + mf >= secs:
break
if nts != lts:
mf = max(mf, nts - lts)
lts = nts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment