Ads 468x60px

Wednesday, November 21, 2012

How to open and close a process from a python script

Hi guys

     I am giving some idea about  how we can start and stop a process using a python script. This will be useful when we need to start a process that is outside the script

I am running two python scripts. One is master script, this script will start the slave script. Slave script will execute continuously upto 5 sec and it will terminated by the master script

Master script

 import time  
 import subprocess  
 #starting process python  
 proc = subprocess.Popen(["python",""],shell=False)  
 #5 sec delay  
 #killing process["kill","-9","%d" %])  
 #waiting for killing  
 print 'poll = ',proc.poll()  

Slave script

 while 1:  
      print "hello"  


It will print hello upto 5 seconds after that it will stop and show this message


Post a Comment