Skip to content

Commit c5b6203

Browse files
committed
timeout error property. Raise from recv_into if timeout time has elapsed
1 parent 743afe6 commit c5b6203

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

adafruit_esp32spi/adafruit_esp32spi_socket.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def recv_into(self, buffer, nbytes: int = 0):
127127
break
128128
# No bytes yet, or more bytes requested.
129129
if self._timeout > 0 and time.monotonic() - last_read_time > self._timeout:
130-
break
130+
raise timeout("timed out")
131131
return num_read
132132

133133
def settimeout(self, value):
@@ -169,4 +169,12 @@ def close(self):
169169
_the_interface.socket_close(self._socknum)
170170

171171

172+
class timeout(TimeoutError):
173+
"""TimeoutError class. An instance of this error will be raised by recv_into() if
174+
the timeout has elapsed and we haven't received any data yet."""
175+
176+
def __init__(self, msg):
177+
super().__init__(msg)
178+
179+
172180
# pylint: enable=unused-argument, redefined-builtin, invalid-name

0 commit comments

Comments
 (0)