On Thu, Jul 16, 2009 at 09:06:32AM -0700, aalex wrote:
> I found http://humanized.com/ProcessManager/
> which is very nice, though the license is not a very common one
Looks like classic 3-part BSD license to me, surely that must be
common. Not that I know much about licenses but anyway.
> Anyways, from what I have experimented so far PSI seems to be *very*
> interesting in that it is C-based, cross-platform, well-documented and
> free. With PSI, is it possible to launch a process in the background
> (or redirecting its stdout to a log file) and store its PID?
To lauch processes in the background you will need os.spawnve() and
friends or subprocess.Popen() depending on your needs. If you want to
redirect the stdin, stdout and stderr you're looking at os.pipe(),
os.dup2(), os.fork() and os.execve() & friends (roughly in that order
I think) if subprocess.Popen() doesn't suit you. They let you do the
classic UNIX stuff, this is basically what ProcessManager does if you
need examples. And if you're going for UNIX daemons don't forget to
control the current working directory, close all other
filedescriptors, set user and group IDs, make sure you're not a
session leader, have no controlling terminal in your session etc.
Actually the best point to start if you want real UNIX daemons is
probably python-daemon[0] (I think it's pretty good but I haven't
scrutinised it's code), but that's geared towards python code being
the daemon so you might have to pull some tricks or use os.execve() as
the main "daemon" code for it, at least read PEP 3143.
What PSI will let you do is once you've got your process you can use
the PID (or find the pid using the psi.process.ProcessTable, but if
you just started the app you should know the pid) to create a
psi.process.Process instance and verify the process is still running
and is well behaving, report on it's metrics etc. You can also use
PSI to check if another instance of your program is running already
before starting a new one and things like that.
Regards
Floris
[0] http://pypi.python.org/pypi/python-daemon/
--
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org