<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def __WaitForInstance(instance, desired_state):
 """ Blocks until instance is in desired_state. """

  print 'Waiting for instance %s to change to %s' % (instance.id, desired_state)
  while True:
      try:
          instance.update()
          state = instance.state
          sys.stdout.write('.')
          sys.stdout.flush()
          if state == desired_state:
              break
      except boto_exception.EC2ResponseError as e:
          logging.info(e)
      #except boto_exception.ResponseError as e:  # This is an alias
      #    logging.info(e)
      time.sleep(5)  
  return