From 78fd2372f6bfb760357c0a85c4fc3a3f241ff553 Mon Sep 17 00:00:00 2001 From: BlindChickens Date: Thu, 7 Jul 2022 00:13:01 +0200 Subject: [PATCH] Fix last line of stream being stuck in buffer --- pyhik/hikvision.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyhik/hikvision.py b/pyhik/hikvision.py index c5c6cdf..e9d2cce 100755 --- a/pyhik/hikvision.py +++ b/pyhik/hikvision.py @@ -492,6 +492,8 @@ def alert_stream(self, reset_event, kill_event): start_event = False parse_string = "" fail_count = 0 + line = "" + buffer = b"" url = '%s/ISAPI/Event/notification/alertStream' % self.root_url @@ -514,8 +516,12 @@ def alert_stream(self, reset_event, kill_event): fail_count = 0 self.watchdog.start() - for line in stream.iter_lines(): + for chunk in stream.iter_content(chunk_size=1): # _LOGGING.debug('Processing line from %s', self.name) + buffer += chunk + if chunk == b"\n": + line = buffer + buffer = b"" # filter out keep-alive new lines if line: str_line = line.decode("utf-8", "ignore") @@ -539,6 +545,7 @@ def alert_stream(self, reset_event, kill_event): else: if start_event: parse_string += str_line + line = "" if kill_event.is_set(): # We were asked to stop the thread so lets do so.