I am creating a python programme which will first run another python file and then every 5 mins it will terminate it and restart it untill I manually stop it
I used call from subprocess to start the file every 5 mins but how can I terminate it?
I am creating a python programme which will first run another python file and then every 5 mins it will terminate it and restart it untill I manually stop it
I used call from subprocess to start the file every 5 mins but how can I terminate it?
 
    
    Python's in-built os.system() function can be used to run any command line.
You can use command kill -9 <program_name> with os.system() as below to kill the other program. You may refer to the following documentation for more clarity.
os.system('killall -9 <program_name>')
or
os.system('pkill <program_name>')
or
os.system('kill -9 <PID>')
 
    
    The call is in the legacy API of subprocess. Instead use the Popen constructor under subprocess - docs here. Once you do this, you can easily send a signal to kill the process after some time as,
p = Popen(args)
p.kill()
p.kill() is OS independent. Hope this helps. Please do comment if you didn't understand.
