tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sleep.py (491B)


      1 import time
      2 import timeit
      3 
      4 # sleep can be lower than requested value in some platforms: https://bugs.python.org/issue31539
      5 # We add padding here to compensate for that.
      6 sleep_padding = 15.0
      7 
      8 def sleep_at_least(sleep_in_ms):
      9    sleep_until = timeit.default_timer() + (sleep_in_ms / 1E3)
     10    time.sleep((sleep_in_ms + sleep_padding) / 1E3)
     11    # Check if the padding was sufficient; if not, sleep again.
     12    while timeit.default_timer() < sleep_until:
     13        time.sleep(sleep_padding / 1E3)