common.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:SNH48Live 作者: SNH48Live 项目源码 文件源码
def mail_on_exception():
    import config
    import mail

    def excepthook(etype, value, tb):
        try:
            script_name = pathlib.Path(__main__.__file__).name
        except AttributeError:
            script_name = 'script'

        if etype.__module__ == 'builtins':
            ename = etype.__name__
        else:
            ename = etype.__module__ + '.' + etype.__name__

        subject = f'[SNH48Live] {script_name} failed with {ename}'
        emsg = ''.join(traceback.format_exception(etype, value, tb))

        if config.main.notifications:
            mail.send_mail(subject, emsg, config.main.mailto)

        sys.stderr.write(emsg)
        sys.exit(1)

    if config.main.notifications:
        mail.init_gmail_client()
    sys.excepthook = excepthook
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号