Writing a simple linux daemon type thing...
jones at jones.jones
Fri Jun 14 06:19:54 CEST 2002
I hope this is a simple question for you guys. I'm new to Python and Linux.
I'm wondering if Python (and this group) can help me.
I want a program to always be running in the background that, connects to
PostgreSQL every few seconds, queries a table, and for each record it finds,
shells out to the system to execute program.
My research indicates that "nohup" might do the trick? So would it be as
simple as writing the program in Python and then puting something like
"nohup python myprog" in the Linux startup sequence (wherever that may be)?
That's my primary goal. Now... assuming I get past that part, I may want to
take it a few steps further later on. I'd be happy if you guys could take a
stab at telling me if these are possible and any tips too...
a) Make it multi-threaded... As I said before, the number of times it
executes the external program equals the number of records it finds in the
table. It would be nice if I could execute the program multiple times
concurrently in a *controlled* manner (depending on my system resources)
instead of having to wait for each one to be done before starting another
b) Make it fail-safe. I would like to figure out how I could re-launch the
program if it was to crash.
P.S. You're probably wondering why I don't just use a trigger. One reason
is that I don't think I can execute an external program from PostgreSQL and
I don't know C to write a wrapper function. Second reason is that because I
am running an external program (out of my "control"), I'm afraid it might
crash, etc and that record will never get processed.
More information about the Python-list