Skip to content

Commit

Permalink
Fix remote stream termination
Browse files Browse the repository at this point in the history
  • Loading branch information
ml31415 committed Jun 22, 2024
1 parent 6dac1e1 commit 51ba36d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions betfair_parser/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

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

0 comments on commit 51ba36d

Please sign in to comment.