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
#1
Hey guys,
First time poster here, looks like a cool community.
My goal here was to build something that managed the lights on my Status Board Zero for my raspberry pi. Using the library provided (https://github.com/ThePiHut/statusboard) I quickly found out that once the script exited, the lights went out. The script I wrote creates a socket on the local loopback and listens for commands. I know that use of eval() on input is just a bad idea, but that's how I made it work. Looking for feedback, preferably constructive
https://github.com/Rhysers/statusboardd
myServer.py (I know I'm not creative when it comes to naming) is the listening script.

Thanks in advance!
Rhys
Reply
#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


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,352 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