from subprocess import Popen
from threading import Timer
p = Popen(['command', 'arg1'])
print(p.pid)
p.terminate()
terminator = Timer(5, p.kill)
terminator.start()
p.wait()
terminator.cancel()
How to kill a process been created by subprocess in python?