The project I'm currently working on works with multiple os.system() calls. I'm working on adding the ability to run these calls in the background. This would start a new thread, call os.system() and redirect all output to /dev/null.
The issue is that I can't think of a best way to end these threads. When I call .join() on a thread running an os.system() call, the system call just takes back over the main thread. I'd like the user to have the ability to terminate these threads.
The solution I've though of was to start one thread, then have that thread start the os.system() call in another thread. The first child thread would continuously check a True/False value. But then I hit the issue of the first child thread terminating the second child thread, so the core issue still remains.
Here is a mock-up of what my code look like now:
import threading
import os
def a():
os.system('ping www.stackoverflow.com > /dev/null')
threads = []
threads.append(threading.Thread(target=a))
threads[0].start()
#Continue doing other stuff
The problem here is that I cannot come up with a stable way to stop these threads.