adafruit / adafruit/Adafruit_CircuitPython_ESP32SPI
socket.settimeout() Argument 0 value meaning differs from cpython
- Dominant language
- Python
- Stars
- 102
- Forks
- 71
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 1
Description
In this library the socket.settimeout function mentions that it treats 0 as to mean block forever until data is received:
https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/blob/0adb75b898a133d929eb14baa2e54b7e9e23899c/adafruit_esp32spi/adafruit_esp32spi_socket.py#L146-L150
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in adafruit_esp32spi/adafruit_esp32spi_socket.py at the settimeout implementation linked in the issue, then compare its behavior with the CPython socket.settimeout documentation. Check whether the underlying ESP32 firmware can distinguish 0, None, and positive timeouts; done means those values follow the requested CPython-compatible semantics where supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100