code: def sleep(duration):
      '''
      Sleeps for duration seconds in increments of 0.5 seconds.
  
      Use this so that the sleep can be interrupted by thread_raise().
      '''
      import time
      start = time.time()
      while True:
          elapsed = time.time() - start
          if elapsed >= duration:
              break
          time.sleep(min(duration - elapsed, 0.5)f sleep(duration):
      '''
      Sleeps for duration seconds in increments of 0.5 seconds.
  
      Use this so that the sleep can be interrupted by thread_raise().
      '''
      import time
      start = time.time()
      while True:
          elapsed = time.time() - start
          if elapsed >= duration:
              break
          time.sleep(min(duration - elapsed, 0.5))
docs: Sleeps for duration seconds in increments of 0.5 seconds.
  
      Use this so that the sleep can be interrupted by thread_raise().