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 the issue of api.get_zone_status_stream not return after timeout #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion brainframe/api/stubs/zone_statuses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import time
from typing import Dict, Generator

import requests
Expand Down Expand Up @@ -51,6 +52,7 @@ def zone_status_iterator():
resp = self._get(req, timeout=timeout)

packets = resp.iter_lines(delimiter=b"\r\n")
timeout_start = time.time()
velovix marked this conversation as resolved.
Show resolved Hide resolved
while True:
try:
packet = next(packets)
Expand All @@ -66,7 +68,10 @@ def zone_status_iterator():
raise bf_errors.ServerNotReadyError(message)

if packet == b'':
continue
if time.time() < timeout_start + timeout:
continue
else:
break

# Parse the line
zone_statuses_dict = json.loads(packet)
Expand Down