Your solution will work, but it will spawn a lot of console windows one after another. To avoid it you can try this:
>>> import subprocess
>>> from time import sleep
>>> si = subprocess.STARTUPINFO()
>>> si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
>>> while True:
subprocess.call('taskkill /F /IM notepad.exe', startupinfo=si)
sleep(1) # delay 1 seconds
2
solved How can one prevent a program from being opened with Python? [closed]