traceback

py.test Tracebacks: Highlight my code, fold frames of framework

py.test Tracebacks: Highlight my code, fold frames of framework Question: Tracebacks of my tests are too long since I use pytest. Pytests includes surrounding code lines and a lot of other information. I like to see this information if the traceback line (frame) is from my code. But I don’t want to see it, if …

Total answers: 3

Get Traceback of warnings

Get Traceback of warnings Question: In numpy we can do np.seterr(invalid=’raise’) to get a traceback for warnings raising an error instead (see this post). Is there a general way for tracing warnings? Can I make python to give a traceback, when a warning is raised? Asked By: embert || Source Answers: Run your program like …

Total answers: 6

python: Is there a downside to using faulthandler?

python: Is there a downside to using faulthandler? Question: Python 3.3 includes a module named faulthandler that displays helpful traceback information if a segfault occurs. (For Python versions prior to 3.3, the module can be obtained from PyPI.) The module is not enabled by default. It is enabled like this: import faulthandler faulthandler.enable() This feature …

Total answers: 1

How can I more easily suppress previous exceptions when I raise my own exception in response?

How can I more easily suppress previous exceptions when I raise my own exception in response? Question: Consider try: import someProprietaryModule except ImportError: raise ImportError(‘It appears that <someProprietaryModule> is not installed…’) When run, if someProprietaryModule is not installed, one sees: (traceback data) ImportError: unknown module: someProprietaryModule During handling of the above exception, another exception occurred: …

Total answers: 3

Get full traceback

Get full traceback Question: How can i get full traceback in the following case, including the calls of func2 and func functions? import traceback def func(): try: raise Exception(‘Dummy’) except: traceback.print_exc() def func2(): func() func2() When i run this, i get: Traceback (most recent call last): File “test.py”, line 5, in func raise Exception(‘Dummy’) Exception: …

Total answers: 5

Python: Traceback codecs.charmap_decode(input,self.errors,decoding_table)[0]

Python: Traceback codecs.charmap_decode(input,self.errors,decoding_table)[0] Question: Following is sample code, aim is just to merges text files from give folder and it’s sub folder. i am getting Traceback occasionally so not sure where to look. also need some help to enhance the code to prevent blank line being merge & to display no lines in merged/master file. …

Total answers: 3

Is there any way to access nested or re-raised exceptions in python?

Is there any way to access nested or re-raised exceptions in python? Question: A common pattern in python is to catch an error in an upstream module and re-raise that error as something more useful. try: config_file = open(‘config.ini’, ‘r’) except IOError: raise ConfigError(‘Give me my config, user!’) This will generate a stack trace of …

Total answers: 3

Remove traceback in Python on Ctrl-C

Remove traceback in Python on Ctrl-C Question: Is there a way to keep tracebacks from coming up when you hit Ctrl+c, i.e. raise KeyboardInterrupt in a Python script? Asked By: Kyle Hotchkiss || Source Answers: Catch the KeyboardInterrupt: try: # do something except KeyboardInterrupt: pass Answered By: icktoofay Catch it with a try/except block: while …

Total answers: 9

Python: Getting a traceback from a multiprocessing.Process

Python: Getting a traceback from a multiprocessing.Process Question: I am trying to get hold of a traceback object from a multiprocessing.Process. Unfortunately passing the exception info through a pipe does not work because traceback objects can not be pickled: def foo(pipe_to_parent): try: raise Exception(‘xxx’) except: pipe_to_parent.send(sys.exc_info()) to_child, to_self = multiprocessing.Pipe() process = multiprocessing.Process(target = foo, …

Total answers: 6