Spawn new process -> get pid

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Feb 5 18:54:57 EST 2008


En Tue, 05 Feb 2008 20:05:04 -0200, breal <hacker.stevenson at 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




More information about the Python-list mailing list