Skip to content

change timeout to retry count in _wait_spi_char #132

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

Merged
merged 2 commits into from
May 25, 2021

Conversation

mikejc58
Copy link
Contributor

@mikejc58 mikejc58 commented Apr 7, 2021

This change modifies the adafruit_esp32spi.py's _wait_spi_char function to use a retry count rather than a 100 millisecond timeout. Since 100 milliseconds is less that a typical garbage collect, the timeout causes spurious timeout exceptions to be reported. The retry count is set to 50, which is about the number of times the existing code will go around its timeout loop in 100 milliseconds.

See the attached file for more details

conclusions.txt

@ladyada
Copy link
Member

ladyada commented Apr 7, 2021

you dont need a time.sleep() in the loop?

@mikejc58
Copy link
Contributor Author

mikejc58 commented Apr 7, 2021

No, I don't think so. There was never a time.sleep in the loop before, and with the retry count of 50, when/if _read_byte does not return the expected value (when it will loop), the existing code loops back and retries with no delay. 50 retries takes about 100 milliseconds, the same as the original timeout. So, in the case where retries are used, the new code performs exactly the same as before.

@mikejc58
Copy link
Contributor Author

mikejc58 commented Apr 7, 2021

Actually, I should verify the 50 retries == 100 milliseconds. I think I might have measured that with instrumentation code in the path...that would reduce the count. I'll get back on this.

@mikejc58
Copy link
Contributor Author

mikejc58 commented Apr 7, 2021

The 50 retries I measured taking 100 milliseconds were with a print statement each time around the loop. The actual time for 50 retries is only 3.3 milliseconds. So the retry loop needs about 1500 retries. I think it should actually do that. To minimize the chance that this modification will cause some changed behavior (other than what is intended), it should work like the old code. The old code would have looped about 1500 times until the 100 millisecond timeout occurred. We certainly could change it to time.sleep(0.01) and retry 10 times (for example), but I don't know if there is any point in that. Does Circuitpython have some use for those sleep cycles?

@mikejc58
Copy link
Contributor Author

mikejc58 commented Apr 7, 2021

After sleeping on it, I think that using time.sleep(0.01) and retrying 10 times is a better choice. If asyncio is eventually going to be supported, all of these timeout loops should be changed.

I'll push that change after I run with that for a while.

@ladyada
Copy link
Member

ladyada commented Apr 7, 2021

ok, ... it is now the exact same timeout as before (?)

@mikejc58
Copy link
Contributor Author

mikejc58 commented Apr 7, 2021

Yes, 100 milliseconds.

@ladyada ladyada requested a review from tannewt April 7, 2021 17:12
@jposada202020
Copy link
Contributor

jposada202020 commented May 25, 2021

@tannewt Do yo have any comments regarding this PR :)
Thanks

@anecdata
Copy link
Member

Just a note that the revised approach to use explicit timing (time.sleep or checking elapsed time in a loop) seems preferable to using a counter to approximate time as the latter would vary across ports and boards.

Copy link
Member

@tannewt tannewt left a 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!

@tannewt tannewt merged commit 61e3863 into adafruit:master May 25, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 1, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO08X to 1.1.1 from 1.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO08x#23 from jposada202020/improving_docs
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > Merge pull request adafruit/Adafruit_CircuitPython_BNO08x#22 from caternuson/iss21

Updating https://github.com/adafruit/Adafruit_CircuitPython_DPS310 to 1.2.6 from 1.2.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_DPS310#17 from jposada202020/correcting_returning_units
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 3.5.10 from 3.5.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#132 from mikejc58/wait_spi_char
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 to 3.3.7 from 3.3.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_PCA9685#36 from jvalrog/fix-servo-example
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_SI5351 to 1.2.8 from 1.2.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_SI5351#21 from jposada202020/changing_assertions
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_TCA9548A to 0.5.0 from 0.4.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_TCA9548A#35 from jposada202020/adding_example_docs_improvement
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.10.1 from 1.10.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#34 from bjnhur/master
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font to 1.5.1 from 1.5.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Bitmap_Font#47 from adafruit/linting
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout to 1.9.3 from 1.9.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#39 from adafruit/linting
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#37 from jposada202020/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_Gizmo to 1.3.2 from 1.3.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_Gizmo#18 from adafruit/linting
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_HID to 5.0.1 from 5.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_HID#69 from jfurcean/fix-led-example
  > Merge pull request adafruit/Adafruit_CircuitPython_HID#70 from FoamyGuy/adding_brightness_codes
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template

Updating https://github.com/adafruit/Adafruit_CircuitPython_ProgressBar to 2.2.0 from 2.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#31 from jposada202020/progressbar_accelerometer
  > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#30 from alimustafashah/master
  > Moved CI to Python 3.7
  > Added help text and problem matcher
  > Added pull request template
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

Successfully merging this pull request may close these issues.

5 participants