Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket.settimeout() Argument 0 value meaning differs from cpython #187

Open
FoamyGuy opened this issue Jan 29, 2024 · 0 comments
Open

socket.settimeout() Argument 0 value meaning differs from cpython #187

FoamyGuy opened this issue Jan 29, 2024 · 0 comments

Comments

@FoamyGuy
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant