docs: def _poll_for_events(h_client, stack_name, action=None, poll_period=5,
                       timeout=60, marker=None):
      '''
      Polling stack events
      '''
      if action:
          stop_status = ('{0}_FAILED'.format(action), '{0}_COMPLETE'.format(action))
          stop_check = lambda a: a in stop_status
      else:
          stop_check = lambda a: a.endswith('_COMPLETE') or a.endswith('_FAILED')
      timeout_sec = timeout * 60
      no_event_polls = 0
      msg_template = ('\n Stack %(name)s %(status)s \n')
      while True:
          events = _get_stack_events(h_client, stack_id=stack_name,
                                     event_args={'sort_dir': 'asc', 'marker': marker})
  
          if not events:
              no_event_polls += 1
          else:
              no_event_polls = 0
              # set marker to last event that was received.
              marker = getattr(events[-1], 'id', None)
              for event in events:
                  # check if stack event was also received
                  if getattr(event, 'resource_name', '') == stack_name:
                      stack_status = getattr(event, 'resource_status', '')
                      msg = msg_template % dict(
                          name=stack_name, status=stack_status)
                      if stop_check(stack_status):
                          return stack_status, msg
  
          if no_event_polls >= 2:
              # after 2 polls with no events, fall back to a stack get
              stack = h_client.stacks.get(stack_name)
              stack_status = stack.stack_status
              msg = msg_template % dict(
                  name=stack_name, status=stack_status)
              if stop_check(stack_status):
                  return stack_status, msg
              # go back to event polling again
              no_event_polls = 0
  
          time.sleep(poll_period)
          timeout_sec -= poll_period
          if timeout_sec <= 0:
              stack_status = '{0}_FAILED'.format(action)
              msg = 'Timeout expired'
              return stack_status, msg