Skip to content

Commit

Permalink
feat: non-blocking mode for recvuntil
Browse files Browse the repository at this point in the history
  • Loading branch information
rqdaA authored and ptr-yudai committed Mar 25, 2024
1 parent a953611 commit 6409a5b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ptrlib/connection/tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def recvuntil(self,
size: int=4096,
timeout: Optional[Union[int, float]]=None,
drop: bool=False,
lookahead: bool=False) -> bytes:
lookahead: bool=False,
sleep_time: float=0.01) -> bytes:
"""Receive raw data until `delim` comes
Args:
Expand All @@ -131,6 +132,7 @@ def recvuntil(self,
timeout (int): Timeout (in second)
drop (bool): Discard delimiter or not
lookahead (bool): Unget delimiter to buffer or not
sleep_time (float): Sleep time after receiving data
Returns:
bytes: Received data
Expand Down Expand Up @@ -160,7 +162,8 @@ def recvuntil(self,
data += self.recv(size, timeout=-1)
except TimeoutError as err:
raise TimeoutError("`recvuntil` timeout", data + err.args[1])
time.sleep(0.01)
if sleep_time > 0:
time.sleep(sleep_time)

for t in delim:
if t in data:
Expand Down

0 comments on commit 6409a5b

Please sign in to comment.