[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Spawn new process -> get pid

breal

2/4/2008 10:59:00 PM

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.

What is the best way to do this? I don't want to replace the current
process with the new one which is looks like os.exec* does.

Thanks.
5 Answers

Gabriel Genellina

2/4/2008 11:34:00 PM

0

En Mon, 04 Feb 2008 20:59:16 -0200, breal <hacker.stevenson@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.
>
> What is the best way to do this? I don't want to replace the current
> process with the new one which is looks like os.exec* does.

Use the subprocess module:
http://docs.python.org/lib/module-subpr...

--
Gabriel Genellina

breal

2/5/2008 12:22:00 AM

0

On Feb 4, 3:34 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
> En Mon, 04 Feb 2008 20:59:16 -0200, breal <hacker.steven...@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.
>
> > What is the best way to do this? I don't want to replace the current
> > process with the new one which is looks like os.exec* does.
>
> Use the subprocess module:http://docs.python.org/lib/module-subpr...
>
> --
> Gabriel Genellina

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?

Thanks

Gabriel Genellina

2/5/2008 5:26:00 AM

0

On 4 feb, 22:21, breal <hacker.steven...@gmail.com> wrote:
> On Feb 4, 3:34 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
>
> > En Mon, 04 Feb 2008 20:59:16 -0200, breal <hacker.steven...@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-subpr...
>
> 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

breal

2/5/2008 10:05:00 PM

0

On Feb 4, 9:25 pm, Gabriel Genellina <gagsl-...@yahoo.com.ar> wrote:
> On 4 feb, 22:21, breal <hacker.steven...@gmail.com> wrote:
>
>
>
> > On Feb 4, 3:34 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
>
> > > En Mon, 04 Feb 2008 20:59:16 -0200, breal <hacker.steven...@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-subpro...
>
> > 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.

Gabriel Genellina

2/5/2008 11:55:00 PM

0

En Tue, 05 Feb 2008 20:05:04 -0200, breal <hacker.stevenson@gmail.com>
escribió:

> 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.

wait() waits until the process finishes. You can't kill it later - it's
already dead :)

> 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.

What means "fully working"? I guess you could try to connect to the port
used, and when the connection succeeds, it's ready.

--
Gabriel Genellina