Spawn new process -> get pid

breal hacker.stevenson at gmail.com
Tue Feb 5 17:05:04 EST 2008


On Feb 4, 9:25 pm, Gabriel Genellina <gagsl-... at yahoo.com.ar> wrote:
> On 4 feb, 22:21, breal <hacker.steven... at gmail.com> wrote:
>
>
>
> > On Feb 4, 3:34 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>
> > > En Mon, 04 Feb 2008 20:59:16 -0200, breal <hacker.steven... at gmail.com>
> > > escribió:
>
> > > > I have a soap server written in Python that acts as an intermediary
> > > > between a web service and an InDesign server.  The indesign server is
> > > > non-threaded, so when all instances are used up I want to create a new
> > > > instance, get the pid, use the process, then kill it.
>
> > > Use the subprocess module:http://docs.python.org/lib/module-subprocess.html
>
> > Thanks for the reply.  Using subprocess.Popen I am able to get and
> > kill the process.  However, the process I am running creates another
> > process (an instance of InDesign Server) so when I kill the first
> > process it doesn't kill the second.  Is there any way to capture both
> > PIDs and kill them?
>
> I assume you're on *nix. Can you modify the first process? Make it a
> project group leader, then kill the whole group. I don't remember the
> details, try `man setpgrp` (or setpg?)
>
> --
> Gabriel Genellina

Ok, so at first I was calling a shell script that called another
program to start.  I have eliminated the middle-man shell script and
am now calling the program directly.  But here is my problem...

I need the program to start fully before I go on any further so that
it is available later in my script.  After it is used I need to kill
the pid of the program I started.  So, I was trying to use
my_process = subprocess.Popen(["/path/to/my/program', "-port", "%s"
%port_number, "-configure", "conf.%s" %port_number], stdout=f1)
my_process.wait()
child_pid = my_process.pid

Is this the right way to do it?  It seems to be returning a different
pid for the process... so when I try to kill it I get a "no such
process" error.

Basically I have five instances of InDesign server running on various
ports.. 18400 - 18404.  When they are all in use, I want to start a
new instance... have it fully running... then use it and kill it.

Any help is appreciated.



More information about the Python-list mailing list