我想弄清楚为什么有时我的 python 脚本会随机从 linux 主机接收到 SIGINT
。
通常调试这个问题的方法是什么
我正在使用
nohup python my_script.py > /dev/null 2>&1&
然后切换到
nohup python my_script.py > myprogram.out 2> myprogram.err&
是否有其他日志和 channel 我可以检查为什么 linux 主机向脚本发送终止命令?
我正在使用 aws ec2 实例。
最佳答案
这样试试:
import datetime
try:
[your_code]
except KeyboardInterrupt as e:
# catch SIGINT
print("{}: {}".format(datetime.datetime.now(), e), flush=True)
except:
# catch unknown exception
print("{}: other exception!".format(datetime.datetime.now()), flush=True)
关于python - 有没有一种方法可以监视导致 linux 中的 python 脚本程序关闭的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52397724/