Python Forum
Built a daemon, almost certinally the wrong way
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Built a daemon, almost certinally the wrong way
#2
(Mar-17-2019, 09:11 PM)rhysers Wrote: I know that use of eval() on input is just a bad idea
In this case, because you're checking that the entire input string is within the valid list, I don't think it's that crazy here. There aren't any situations where you're running unknown code, as it needs an exact match.

That said, I think I'd still rather see a dict...
valid = {"internetGood": internetGood, 'internetOK': internetOK, 'internetBad': internetBad, 'alexaGood': alexaGood, 'alexaWarning': alexaWarning, 'alexaBad': alexaBad, 'stop': stop, 'noUpdates': noUpdates, 'secUpdates': secUpdates, 'updates': updates, 'needReboot': needReboot}

# ... and then...
if stringOut in valid:
    valid[stringOut]()
...if for no other reason than it allows you to change your architecture and rewrite either end of your code, without having to rewrite both the server and the client at the same time.
Reply


Messages In This Thread
RE: Built a daemon, almost certinally the wrong way - by nilamo - Mar-18-2019, 08:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A Python daemon that sends Twilio SMS Alerts when top metrics exceed thresholds rootVIII 0 2,379 Mar-25-2019, 03:46 AM
Last Post: rootVIII

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020