FoamyGuy · GitHub

In this library the socket.settimeout function mentions that it treats 0 as to mean block forever until data is received:

def settimeout(self, value):
"""Set the read timeout for sockets.
If value is 0 socket reads will block until a message is available.
"""
self._timeout = value

But in CPYthon the opposite is true: https://docs.python.org/3/library/socket.html#socket.socket.settimeout

A value of 0 is used to mean non-blocking or return immediately if no data is present, and value of None is used for blocking which would match the current behavior of esp32spi_socket.settimeout(0).

I'm not certain if we are stuck with this difference due to something in the underlying esp32 firmware or not. But if possible I think it would be best to try to match the cpython behavior here. So a value of 0 would be changed to be non-blocking, None would be supported to indicate blocking, and non-zero numbers would continue to behave the same.

As the code is now it means if you want non-blocking behavior you need to specify a really small timeout like 0.01 which isn't necessary with cpython.

Read the original on github.com ↗