question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sys.excepthook not work

See original GitHub issue
def 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:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
marcilioLemoscommented, Sep 16, 2022

The solution above sounds fine though it does not catch exceptions raised during app startup (i.e. @app.on_event(“startup”)) .

0reactions
alenzo-pinccommented, Oct 6, 2022

I need to add a word of warning here - I had to remove the workaround I described earlier due to the FastAPI upgrade to 0.85 and consequently a starlette upgrade.

Details can be found here: https://stackoverflow.com/questions/73927410/pytest-fixtures-sqalchemy-connections-not-closing-when-running-in-docker

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found