-
Notifications
You must be signed in to change notification settings - Fork 175
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
Requests to luftdaten should be in try except #79
Conversation
Requests to luftdaten should be in try except block. If script runs in background and and network (e.g. DNS) error occured, the script stops running.
I must preface this with: I didn't write the luftdaten script, and I'm not familiar with their API beyond what I can glean from brushing up on the documentation. While I agree in principle, a bare While a hard fail is pretty nasty, it's probably better than the script quietly failing indefinitely while squashing any useful debug output. I can see a few improvements to this script that might go nicely with your proposal, not least of all:
I don't expect you to make all of these changes, but if you could at least update the Thank you for taking the time to make a PR! |
:) won't do the work for a commercial poduct. I Think I helped enought that it dont silently crash
…-------- Ursprüngliche Nachricht --------Von: Philip Howard <notifications@github.com> Datum: 05.08.20 11:50 (GMT+01:00) An: pimoroni/enviroplus-python <enviroplus-python@noreply.github.com> Cc: ulrischa <uli@ulrischa.de>, Author <author@noreply.github.com> Betreff: Re: [pimoroni/enviroplus-python] Requests to luftdaten should be in try except (#79)
I must preface this with: I didn't write the luftdaten script, and I'm not familiar with their API beyond what I can glean from brushing up on the documentation.
While I agree in principle, a bare Except clause is an antipattern in Python- it should trap the specific network error and do something useful such as retry sending the data a limited number of times, just in case it's a temporary exception.
While a hard fail is pretty nasty, it's probably better than the script quietly failing indefinitely while squashing any useful debug output.
I can see a few improvements to this script that might go nicely with your proposal, not least of all:
Moving update_time = time.time() to before send_to_luftdaten so the data sending function has the full 145??? seconds to retry sending the values. Though I can't see any fearture for sending a timestamp to luftdaten.
Adding python logging, so we can log success/failure states and other info with timestamps, this is illustrated nicely here: https://github.com/pimoroni/enviroplus-python/blob/7452b88562c25344ecf9e8eed9b13325d4aef4e6/examples/all-in-one-no-pm.py#L22-L31
I don't expect you to make all of these changes, but if you could at least update the try/catch to produce some useful debug output it would be a good start that I could merge and promote the rest of this to an Issue.
Thank you for taking the time to make a PR!
—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
|
Well it's MIT code for an open data service, but I understand. I can't merge a PR that exchanges one kind of broken for another, however, so I'll promote this to an issue and find time to give this example a proper once over. Thanks again! |
Can't see what is so bad with the except: pass. It just skips the current request to luftdaten and tries again in the time specified in the main loop.Logging would be nice, but to be honest the whole script has no logging and is kind of beta. I also commented out line 186. display_status crashed the script also from time to time. Also no config variables defined in one place (WIDTH, HEIGHT, comp_value).
-------- Ursprüngliche Nachricht --------Von: Philip Howard <notifications@github.com> Datum: 05.08.20 13:30 (GMT+01:00) An: pimoroni/enviroplus-python <enviroplus-python@noreply.github.com> Cc: ulrischa <uli@ulrischa.de>, Author <author@noreply.github.com> Betreff: Re: [pimoroni/enviroplus-python] Requests to luftdaten should be in try except (#79)
Well it's MIT code for an open data service, but I understand.
I can't merge a PR that exchanges one kind of broken for another, however, so I'll promote this to an issue and find time to give this example a proper once over.
Thanks again!
—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
|
Requests to luftdaten should be in try except block. If script runs in background and and network (e.g. DNS) error occured, the script stops running.