python中的信号处理不适用于多线程程序

时间:2015-05-28 09:33:19

标签: python multithreading process signals

我有一个多线程程序,其流程如下:

主程序:

#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)

清理代码:

def cleanup_function():
    #send a kill to the main program using os.getpid()

我面临清理问题。当我调用主程序并抛出异常时,信号正确发送,主程序获取SIGINT,但所有子线程都没有正确终止。我做错了什么。我应该使用SIGTERM吗?这有助于杀死所有子线程和子进程产生吗?

0 个答案:

没有答案