sys.excepthook not work
See original GitHub issuedef my_excepthook(exc_type, exc_value, tb):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, tb)
return
msg = ' Traceback (most recent call last):\n'
for filename, linenum, funcname, source in traceback.extract_tb(tb):
msg += "%-23s:%s '%s' in %s() \n" % (filename, linenum, source, funcname)
msg += ' %s: %s\n' %(exc_type.__name__, exc_value)
logger.info(json.dumps({'msg':msg}))
sys.excepthook = my_excepthook
I want to use my_excepthook to process except, but it is not work in fastapi
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Why doesn't sys.excepthook work? - Stack Overflow
-->EDIT My Problem is caused by a bug in idle-python 3.4 because now i tried to run the code by interpreter python (command...
Read more >Issue 11705: sys.excepthook doesn't work in imported modules
It seems like the sys.excepthook function is unaware of the logging module. Here is an example: #! /usr/bin/env python2.7 import logging, sys ...
Read more >Python sys.excepthook - Waylon Walker
I am working on a quick and dirty python script designed to take screenshots and land them on my website in a single...
Read more >Error in sys.excepthook: Original exception was:
I get the following error when using hoomd.md.pair.table . The code seems to run fine and finish executing. But after it shows "run...
Read more >Python Examples of sys.excepthook - ProgramCreek.com
def _getexcepthook(): "Return a function that can be used as except hook for uncaught exceptions." if not sys.argv[0]: # We are in interactive...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The solution above sounds fine though it does not catch exceptions raised during app startup (i.e. @app.on_event(“startup”)) .
Interesting… I wonder if you could have raised and HTTPException in the middleware to get your session dependency to close the connection and roll back?