-
Notifications
You must be signed in to change notification settings - Fork 50
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
loop() timeout parameter should be absolute #169
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR correctly addresses the comment:
loop() is blocking because _wait_for_msg() is blocking, which is because _sock_exact_recv() is blocking as currently implemented
@vladak I have some questions:
- Do we need to change any example files to reflect the modifications to
loop()
- Have you tested this on hardware yet?
I'm doing some testing on adafruit/Adafruit_CircuitPython_ESP32SPI#167 which is aiming to make the esp32spi socket match the CPython socket behavior as close as possible, that led me to this problem and solution proposed here. @brentru From my testing I think I can answer these:
1: The examples do not need to change as a result of the change in this PR because there is a default provided for 2: I have tested the change here in #169 successfully in 3 contexts:
The asterisks for ESP32SPI is because my testing was performed on the version of ESP32SPI from adafruit/Adafruit_CircuitPython_ESP32SPI#167 rather than the currently stock released version. When using that modified ESP32SPI + The version from this PR the example scripts are working as intended and the blocking (or lack thereof) behavior of On a somewhat related note, I do think it would be good to tweak the time value here: Adafruit_CircuitPython_MiniMQTT/examples/esp32spi/minimqtt_pub_sub_nonblocking_esp32spi.py Line 112 in 40b9096
Im not certain of the root cause, but I started suspecting we were publishing data "too fast" and that was causing it to start failing. I backed that off to a 3 second sleep and it's been running steadily without having the same problem. With regards to question 1 above: this change is not necessarily required, but it does seem good for stability. |
EXCELLENT! Thank you for testing.
@vladak Are you able to increase the delay value on the line specified by @FoamyGuy? After that, I'd like to go ahead and merge this PR. |
This is super awesome if someone comes to the rescue and tests the code in the PR for you ! Thanks @FoamyGuy ! I have to admit I fired off the PR primarily to get the discussion started and skimped on proper testing. That said, I will think about a unit test for this. |
Okay, changed to 3 seconds. |
I'm doing some more testing on this and all the other changes associated with the ESP32SPI socket compatibility and I noticed that the I opened: adafruit/Adafruit_CircuitPython_Wiznet5k#125 over there to address this and successfully tested the adafruitio ethernet example in this repo with those changes (and the changes from this PR). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thank you @vladak!
Merging this one now along with the changes to ESP32SPI library and others that were all tied together in various ways.
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 6.0.0 from 5.0.6: > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#167 from dhalbert/compatible-socket Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 7.4.0 from 7.3.2: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#169 from vladak/loop_vs_timeout > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#162 from adafruit/settings_dot_toml > Update .pylintrc, fix jQuery for docs > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#167 from tekktrik/main > Run pre-commit > Update pre-commit hooks > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#164 from zbauman3/zane/cert-key-pair-example Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 2.0.0 from 1.14.1: > Merge pull request adafruit/Adafruit_CircuitPython_Requests#135 from FoamyGuy/remove_backward_compat Updating https://github.com/adafruit/Adafruit_CircuitPython_WSGI to 2.0.0 from 1.1.16: > Merge pull request adafruit/Adafruit_CircuitPython_WSGI#20 from FoamyGuy/compatibility_refactor > Merge pull request adafruit/Adafruit_CircuitPython_WSGI#19 from tekktrik/dev/fix-packaging Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
This changes the way how loop() deals with the timeout parameter. I think the original idea was to wait for the timeout and then return what was received in the mean time, regardless of whether anything was actually received. This means that the loop() will always return after the timeout, i.e. not earlier (assuming no fatal error happened).
Inspired by #68 (comment) and the discussion in PR #168.