首页 > 解决方案 > Capturing SIGTERM signal Heroku

问题描述

So i finally found how to capture the signal from this site "https://pymotw.com/2/signal/" , I now can capture most of the kill signals like SIGINT, SIGUSR1, SIGUSR2.... all except the SIGTERM which heroku uses for some reason when I get a SIGTERM my script just exit instead of capturing the signal and do some work, Can Anyone tell me if I'm doing something wrong? I'm testing with the command "kill -INT $pid", i can capture every kill signals Except the SIGTERM, THANKS....

Code :

run = false
def receive_signal(signum, stack):
    print("Received:", signum)
    global run
    run = False 

signal.signal(signal.SIGUSR1,receive_signal)
signal.signal(signal.SIGUSR2, receive_signal)
signal.signal(signal.SIGINT, receive_signal)
signal.signal(signal.SIGTERM, receive_signal)

print("My PID is:", os.getpid())

while run:
      main() 

标签: pythonherokutelegram-bot

解决方案


推荐阅读