diff --git a/betfair_parser/stream.py b/betfair_parser/stream.py index 9104f51..0cb059b 100644 --- a/betfair_parser/stream.py +++ b/betfair_parser/stream.py @@ -177,6 +177,8 @@ def iter_changes(self, stream: io.RawIOBase) -> Iterable[ChangeMessageType]: while True: msg = self.esm.receive(stream) + if not msg: + return if isinstance(msg, ChangeMessageType): # type: ignore[arg-type,misc] yield msg @@ -191,6 +193,8 @@ def iter_changes_and_write( with open(path, "ab") as f: while True: raw_msg = stream.readline() + if not raw_msg: + return msg = self.esm.receive_bytes(raw_msg) if isinstance(msg, ChangeMessageType): # type: ignore[arg-type,misc] yield msg @@ -268,6 +272,8 @@ async def iter_changes_async(self, stream: AsyncStream) -> AsyncGenerator[Change while True: msg = self.esm.receive_bytes(await stream.readline()) + if not msg: + return if isinstance(msg, ChangeMessageType): # type: ignore[arg-type,misc] yield msg @@ -283,6 +289,8 @@ async def iter_changes_and_write_async( with open(path, "ab") as f: while True: raw_msg = await stream.readline() + if not raw_msg: + return msg = self.esm.receive_bytes(raw_msg) if isinstance(msg, ChangeMessageType): # type: ignore[arg-type,misc] yield msg