Skip to content

Added timeout which raises an exception to avoid an infinite loop #35

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 4 commits into from
Feb 3, 2021
Merged

Added timeout which raises an exception to avoid an infinite loop #35

merged 4 commits into from
Feb 3, 2021

Conversation

BiffoBear
Copy link

While instantiating an RFM69 I found that the RFM driver was hanging because self.mode_ready was never True. Added a 1 second timeout that raises an exception. We should discuss the exception type, error message and timeout duration.

@ladyada ladyada requested a review from brentru January 31, 2021 03:13
Copy link
Contributor

@jerryneedell jerryneedell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.. I've never run into it having here but I agree taht the timeout is a good idea.

You will have to run 'black' on the code to keep CI happy. It want the single quotes to be double quotes soon the error message text. If ou are not familiar with black, see https://learn.adafruit.com/improve-your-code-with-pylint/black

I have tested the change on a Raspberry Pi zeroW with RFM69 bonnet. No problems.

while not self.mode_ready:
pass
if (time.monotonic() - start) >= 1:
raise RuntimeError('Operation mode failed to set.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black wants double quotes here...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change to double quotes. Thanks for the link about Black.

Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BiffoBear This looks OK to me,

We should discuss the exception type, error message and timeout duration.

What do you mean by this?

@BiffoBear
Copy link
Author

@BiffoBear This looks OK to me,

We should discuss the exception type, error message and timeout duration.

What do you mean by this?

I normally write code for my own consumption, so I would like a little feedback regarding RuntimeError being the correct error type. Also whether the message is clear enough/. I'm already thinking that "Operation mode changed timed out." might be more descriptive.

@brentru brentru merged commit 7385419 into adafruit:master Feb 3, 2021
@BiffoBear BiffoBear deleted the add-timeout-to-op-mode_setter branch February 3, 2021 23:02
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 10, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_CharLCD to 3.3.7 from 3.3.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#57 from BiffoBear/fix-home-docstring

Updating https://github.com/adafruit/Adafruit_CircuitPython_DymoScale to 1.1.2 from 1.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_DymoScale#10 from adafruit/REUSE
  > Added pre-commit-config file

Updating https://github.com/adafruit/Adafruit_CircuitPython_EMC2101 to 1.1.3 from 1.1.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_EMC2101#4 from MaxBec/hotfix_pwm_freq

Updating https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch to 1.2.4 from 1.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_FocalTouch#19 from kmatch98/add_irq

Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 5.1.2 from 5.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#105 from jfurcean/fix_api_docs
  > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#104 from adafruit/dherrada-patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_RFM69 to 2.1.2 from 2.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_RFM69#35 from BiffoBear/add-timeout-to-op-mode_setter

Updating https://github.com/adafruit/Adafruit_CircuitPython_PIOASM to 0.1.4 from 0.1.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_PIOASM#5 from dglaude/patch-1

Updating https://github.com/adafruit/Adafruit_CircuitPython_ProgressBar to 1.3.6 from 1.3.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_ProgressBar#24 from adafruit/REUSE
  > Added pre-commit-config file

Updating https://github.com/adafruit/Adafruit_CircuitPython_RTTTL to 2.4.4 from 2.4.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_RTTTL#23 from adafruit/dherrada-patch-1
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.

3 participants