code: def alert_stream(self, reset_event, kill_event):
          _LOGGING.debug('Stream Thread Started: %s, %s', self.name, self.cam_id)
          start_event = False
          parse_string = ""
          fail_count = 0
          url = '%s/ISAPI/Event/notification/alertStream' % self.root_url
          while True:
              try:
                  stream = self.hik_request.get(url, stream=True,
                                                timeout=(CONNECT_TIMEOUT,
                                                         READ_TIMEOUT))
                  if stream.status_code == requests.codes.not_found:
                      url = '%s/Event/notification/alertStream' % self.root_url
                      stream = self.hik_request.get(url, stream=True)
                  if stream.status_code != requests.codes.ok:
                      raise ValueError('Connection unsucessful.')
                  else:
                      _LOGGING.debug('%s Connection Successful.', self.name)
                      fail_count = 0
                      self.watchdog.start()
                  for line in stream.iter_lines():
                      if line:
                          str_line = line.decode("utf-8", "ignore")
                          if str_line.find('<EventNotificationAlert') != -1:
                              start_event = True
                              parse_string += str_line
                          elif str_line.find('</EventNotificationAlert>') != -1:
                              parse_string += str_line
                              start_event = False
                              if parse_string:
                                  tree = ET.fromstring(parse_string)
                                  self.process_stream(tree)
                                  self.update_stale()
                                  parse_string = ""
                          else:
                              if start_event:
                                  parse_string += str_line
                      if kill_event.is_set():
                          break
                      elif reset_event.is_set():
                          raise ValueError('Watchdog failed.')
                  if kill_event.is_set():
                      _LOGGING.debug('Stopping event stream thread for %s',
                                     self.name)
                      self.watchdog.stop()
                      self.hik_request.close()
                      return
                  elif reset_event.is_set():
                      raise ValueError('Watchdog failed.')
              except (ValueError,
                      requests.exceptions.ConnectionError,
                      requests.exceptions.ChunkedEncodingError) as err:
                  fail_count += 1
                  reset_event.clear()
                  _LOGGING.warning('%s Connection Failed (count=%d). Waiting %ss. Err: %s',
                                   self.name, fail_count, (fail_count * 5) + 5, err)
                  parse_string = ""
                  self.watchdog.stop()
                  self.hik_request.close()
                  time.sleep(5)
                  self.update_stale()
                  time.sleep(fail_count * 5)
                  continue