我有一个多线程程序,其流程如下:
#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()
def some_function():
#kill the states of the sub-threads generated by main core_logic()
os.kill(processid, sigint)
def cleanup_function():
#send a kill to the main program using os.getpid()
我面临清理问题。当我调用主程序并抛出异常时,信号正确发送,主程序获取SIGINT,但所有子线程都没有正确终止。我做错了什么。我应该使用SIGTERM吗?这有助于杀死所有子线程和子进程产生吗?