Starting a third party application

Arild Hansen arildh at stud.cs.uit.no
Tue Feb 20 03:31:36 EST 2001


Thx, worked just fine! I guess the "cs.uit.no" means that I didn't have to
look too far to get an answer :) 

A. Hansen


On 19 Feb 2001 johnm at cs.uit.no wrote:

> Arild Hansen <arildh at stud.cs.uit.no> writes:
> 
> > I'm trying to make a small module that executes a third party application
> > (for example gcalc or whatever). I do this using
> > os.system("applicationname &") and then the program enters a while loop
> > waiting for some external signal. When this signal arrives, I want the
> > program to make a sys.exit(1) and terminate itself AS WELL AS the third
> > party application it started. The code looks something like:
> > 
> > os.system("applicationame &")
> > while continue:
> > 	if signal:
> > 		continue = FALSE
> > 
> > 
> > My problem is that when the program gets the signal and terminates, the
> > third party application is still running. How do I solve this problem?
> 
> Maybe you should take a look at fork, exec, kill and wait (or spawn if
> you use one of the MS Windows variants). This example should do
> something similar:
> 
> import os
> import time
> 
> child = os.fork()
> if child:
>     print "blabla"
>     time.sleep(2)
>     os.kill(child, 3) # or some other signal
>     os.wait(child)
> else:
>     print "Child, starting /bin/sleep"
>     os.execv("/bin/sleep", ["/bin/sleep", "32"])
>     os.exit(-1) # Shouldn't happen, but in case exec fails
> 
> 




More information about the Python-list mailing list