View Single Post
Brad
Selfish Heathen
 
Join Date: May 2004
Location: Zone of Pain
 
2021-05-29, 16:11

Looks like you got this solved before I saw it, but I guess I'll add my two cents on a few small thingsā€¦

Quote:
Originally Posted by turtle View Post
I know I can remove the "print" but I'm using that since I'm running it in screen.
Although using plain "print" is (rightfully) shunned for libraries and some backend services, I think it's perfectly fine for a one-off personal script like this, especially since you could simply redirect stdout/stderr into a couple of files and then look at those files in an independent shell or process to observe your script's behavior.

Quote:
Originally Posted by turtle View Post
Heck, it barked at me because I mixed spaces and tabs to indentation.
Welcome to Python. "Whitespace is important", as some Pythonistas would say. I'm sure it feels weird at first, but most folks I've known come to love Python's formatting rules pretty quickly, at least if they're writing a lot of Python on a daily basis. If you're interested in doing a lot more Python coding, I'd be happy to talk at length about PEP 8, flake8, and black for more opinionated general code formatting.

Quote:
Originally Posted by turtle View Post
There is no process running and I would expect nor a PID file ever actually created:
It may not be obvious at a glance, but I think this script is using the third-party daemonize library. If you didn't install that yourself, I wouldn't be surprised if it was already installed by some other Raspberry Pi software. I think I tried using daemonize many years ago, and I vaguely remember it being pretty fiddly, and I think I gave up on it. In general, using this (or the better-supported python-daemon library) likely requires a bit deeper Python knowledge than you have right now. You probably want to be familiar with context managers, threads, signal handling, and various file handle objects to make this work well; you might be better off just letting the caller deal with the process/stdin/stdout/signals management.

I like chucker's systemd service suggestion and would recommend that over manual daemon setup.

The quality of this board depends on the quality of the posts. The only way to guarantee thoughtful, informative discussion is to write thoughtful, informative posts. AppleNova is not a real-time chat forum. You have time to compose messages and edit them before and after posting.
  quote