Skip to content

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

Open
@FoamyGuy

Description

@FoamyGuy

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @FoamyGuy

        Issue actions

          socket.settimeout() Argument 0 value meaning differs from cpython · Issue #187 · adafruit/Adafruit_CircuitPython_ESP32SPI