у меня есть это простое flask приложение:
def handle_exception(exc_type, exc_value, exc_traceback):
print("Hello")
dd = "test"
sys.excepthook = handle_exception
logger.info("a %s- b: %s" % dd)
# the logger above will raise exception
if __name__ == '__main__':
# Start the app
app.run(host='0.0.0.0', threaded=True)
handle_exception никогда не вызывался, но в stdout / err я получаю:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1434, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/git/app/app.py", line 132, in <module>
logger.info("a %s- b: %s" % dd)
TypeError: not enough arguments for format string
как заставить его вызывать handle_exception ? там мне нравится обрабатывать все исключения, которые не были пойманы אם