python - 有没有一种方法可以监视导致 linux 中的 python 脚本程序关闭的原因?

标签 python linux amazon-web-services amazon-ec2

我想弄清楚为什么有时我的 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/

相关文章:

c - 时间延迟 (Linux)/(Windows)

amazon-web-services - 创建 AWS 账户配置的备份

python - 我可以从 aws s3 恢复下载吗?

sql - AWS 雅典娜 : Unsupported correlated subquery type but it works on Mysql and other flavors

python - 角色只在鼠标在屏幕上移动时保持移动?

linux - Linux下的动态内存管理

python - 根据 Pandas 中的另一列连接一组列值

linux - 如何从 Linux 内核中的 PID 获取进程描述符?

Python 文本文件之间的日期/时间转换

python - 组织 Django 字段集的最佳方式