In a recent project, I want to debug my program in production use state. The production environment is very complicated so I want to debug the program whenever I find a problem.
This is what I want to achieve: whenever I want to debug, I will send a kill signal to the program and hopefully pdb debugger will appear. It is something like this:
import pdb
import signal
import time
def handler(signal, frame):
pdb.set_trace()
signal.signal(signal.SIGTERM, handler)
a=1
while True:
a+=1
time.sleep(1)
However, since I have to run the program with nohup
, all output will be redirected to nohup.out, so there's no way I can interact with pdb.
Is there anything similar to do this?
nohup python myprog.py &
to run the program. When I kill the process, it didn't seem to enter pdb properly:wangc@lion:~/workspace/temp> kill 2684 wangc@lion:~/workspace/temp> --Return-- > /home/wangc/workspace/temp/wwtest.py(10)handler()->None -> pdb.set_trace()
– Swordtail