Let's talk about the sub-process mechanism in Python
First, we could create a subprocess by using:
process_instance = subprocess.Popen(
["ping", "google.com"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
preexec_fn=os.setsid
)
Then, you could kill it by using:
pid = process_instance.pid
os.killpg(os.getpgid(pid), signal.SIGINT) # This is typically initiated by pressing Ctrl+C
# or
os.killpg(os.getpgid(pid), signal.SIGTERM)
os.killpg(os.getpgid(pid), signal.SIGKILL)
You could use from multiprocessing import Manager; share_dict = Manager().dict()
to share information between different processes or threadings in Python.
with Manager() as manager:
d = manager.dict()
p = Process(target=f, args=(d, ))
p.start()
p.join()
print(d)