Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last line of stream being stuck in buffer #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pyhik/hikvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand All @@ -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.
Expand Down