'How to kill a subprocess when it goes interactive in Python

I need to run several subprocess.run in a loop. Most of the time, if the exe called in the subprocess succeed nothing happen. But in some cases, usually when something is wrong related to what happen in the exe itself, it starts to be interactive: a window pop-up and expect the user to interact (basically, just click on OK and that's all).

As I need to let the code run alone, I want to kill all the subprocess.run when an action of the user is expected.

I already tried the timeout solution but each subprocess have very different computing times so it does not really fit with my issue.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source