I have a multi threaded program with the flow as below:
Main program:
#Listen to the signal
signal.signal(signal.SIGINT, some_function)
#Actual logic by calling some other function, which spawns multiple threads
try:
core_logic() <--- any exception here will invoke the cleanup_function()
except:
cleanup_function()
some_function code
def some_function():
#kill the states of the sub-threads generated by main core_logic()
os.kill(processid, sigint)
cleanup code:
def cleanup_function():
#send a kill to the main program using os.getpid()
I'm facing problems with the cleanup. When I invoke the main program and when an exception is thrown, the signal is sent correctly and the main program gets the SIGINT, but all the sub-threads are not terminated correctly. What mistake am I doing. Should I use SIGTERM instead? Will that help in killing all the sub-threads and child process spawned?