I have a requirement where I have to launch multiple applications, get each of their stdout,stderr and these applications run infinitely. The processes do not exchange/share data and are independent of each other. To do variable stress tests, their timeouts might be different.
For eg:
app1 -> 70sec
app2 -> 30sec
.
.
appN -> 20sec
If these were multiple apps with one common timeout, I would have wrapped it in a timed while loop and killed all processes in the end.
Here are some approaches I think should work:
- A timer thread for each app, which reads stdout and as soon as it expires, kills the process. The process is launched within the thread
- One timer thread that loops through a dictionary of pid/process_objects:end_time for each process and kills the process when its end_time is >= current time
I have tried using asyncio gather, but it doesn't fully meet my needs and I have faced some issues on Windows.
Are there any other approaches that I can use?