class_docstr: A threadsafe, singleton wrapper for time.sleep that improves accuracy.
  
  The time.sleep function is inaccurate and sometimes returns early or late. To
  improve accuracy, this class sleeps for a shorter time than requested and
  enters a spin lock for the remainder of the requested time.
  
  The offset is automatically calibrated based on when the thread is actually
  woken from sleep by increasing/decreasing the offset halfway between its
  current value and `_MIN_OFFSET`.
  
  Accurate to approximately 5ms after some initial burn-in.
  
  Args:
    initial_offset: The initial amount to shorten the time.sleep call in float
        seconds.
  Raises:
    ValueError: When `initial_offset` is less than `_MIN_OFFSET`.
docstr: Sleeps until the requested time.
docstr_tok: ["Sleeps","until","the","requested","time","."]
code: def sleep_until(self, wake_time):
      """Sleeps until the requested time."""
      delta = wake_time - time.time()
  
      if delta <= 0:
          return
  
      # Copy the current offset, since it might change.
      offset_ = self.offset
  
      if delta > offset_:
          time.sleep(delta - offset_)
  
      remaining_time = time.time() - wake_time
      # Enter critical section for updating the offset.
      with self._lock:
          # Only update if the current offset value is what was used in this call.
          if self.offset == offset_:
              offset_delta = (offset_ - Sleeper._MIN_OFFSET) / 2
              if remaining_time > 0:
                  self.offset -= offset_delta
              elif remaining_time < -Sleeper._MIN_OFFSET:
                  self.offset += offset_delta
  
      while time.time() < wake_time:
          pass
  
file_path: magenta/magenta/common/concurrency.py
imports: import functools
  import threading
  import time
label_desc: Use image node_id 5 for calling the Sleeper obj's underlying member method code with example usage: obj.sleep_until(wake_time) without return types