From b1872289cb4f3574ade4716c45f9ac7e976b6cb0 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Tue, 26 May 2020 21:40:24 +0300 Subject: fixed eof handling --- kvmd/clients/streamer.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'kvmd/clients') diff --git a/kvmd/clients/streamer.py b/kvmd/clients/streamer.py index 72e2060f..91267bef 100644 --- a/kvmd/clients/streamer.py +++ b/kvmd/clients/streamer.py @@ -61,20 +61,24 @@ class StreamerClient: ) as response: aiotools.raise_not_200(response) reader = aiohttp.MultipartReader.from_response(response) + while True: frame = await reader.next() # pylint: disable=not-callable if not isinstance(frame, aiohttp.BodyPartReader): raise RuntimeError("Expected body part") + if hasattr(frame, "_content"): - # FIXME: An ugly workaround for: - # Multiple access to StreamReader in eof state, might be infinite loop if frame._content.is_eof(): # pylint: disable=protected-access break + data = bytes(await frame.read()) + if not data: + break + yield ( (frame.headers["X-UStreamer-Online"] == "true"), int(frame.headers["X-UStreamer-Width"]), int(frame.headers["X-UStreamer-Height"]), - bytes(await frame.read()), + data, ) except Exception as err: # Тут бывают и ассерты, и KeyError, и прочая херня из-за корявых исключений в MultipartReader raise StreamerError(f"{type(err).__name__}: {err}") -- cgit v1.2.3