traceback

Print stacktrace from C code with embedded lua

夙愿已清 提交于 2019-11-30 08:13:38
If I understand this correctly, Lua by default will call the debug library "debug.traceback" when an error occurs. However, when embedding Lua into C code like done in the example here: Simple Lua API Example We only have available the error message on the top of the stack. i.e. if (status) { /* If something went wrong, error message is at the top of */ /* the stack */ fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1)); /* I want to print a stacktrace here. How do I do that? */ exit(1); } How do I print the stack trace from C after the initial error? Nicol Bolas Lua by default

traceback() for interactive and non-interactive R sessions

帅比萌擦擦* 提交于 2019-11-30 01:31:15
I observed a different between an interactive and non-interaction R session about traceback() which I do not understand. For the code below, it will produce an error, but in an interactive R session, I can see the traceback information, whereas if I save the code to test.R and call it via Rscript test.R or R -f test.R , I can no longer see the traceback: f = function() { on.exit(traceback()) 1 + 'a' } f() In an interactive R session: > f = function() { + on.exit(traceback()) + 1 + 'a' + } > f() Error in 1 + "a" : non-numeric argument to binary operator 1: f() Non-interactive execution: $

How do I use Django's logger to log a traceback when I tell it to?

泪湿孤枕 提交于 2019-11-30 00:57:25
问题 try: print blah except KeyError: traceback.print_exc() I used to debug like this. I'd print to the console. Now, I want to log everything instead of print, since Apache doesn't allow printing. So, how do I log this entire traceback? 回答1: You can use python's logging mechanism: import logging ... logger = logging.getLogger("blabla") ... try: print blah # You can use logger.debug("blah") instead of print except KeyError: logger.exception("An error occurred") This will print the stack trace and

Remove traceback in Python on Ctrl-C

有些话、适合烂在心里 提交于 2019-11-30 00:33:00
问题 Is there a way to keep tracebacks from coming up when you hit Ctrl + c , i.e. raise KeyboardInterrupt in a Python script? 回答1: import sys try: # your code except KeyboardInterrupt: sys.exit(0) # or 1, or whatever Is the simplest way, assuming you still want to exit when you get a Ctrl + c . If you want to trap it without a try/except, you can use a recipe like this using the signal module, except it doesn't seem to work for me on Windows.. 回答2: Try this: import signal import sys signal.signal

DistributionNotFound error after upgrading pip

萝らか妹 提交于 2019-11-29 13:56:52
问题 In reading about virtualenv here I realized I didn't have pip 1.3+, so I ran pip install --upgrade pip and now when I run pip --version i get the following: Traceback (most recent call last): File "/usr/local/bin/pip", line 5, in <module> from pkg_resources import load_entry_point File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 2807, in <module> parse_requirements(__requires__),

Print stacktrace from C code with embedded lua

让人想犯罪 __ 提交于 2019-11-29 11:12:03
问题 If I understand this correctly, Lua by default will call the debug library "debug.traceback" when an error occurs. However, when embedding Lua into C code like done in the example here: Simple Lua API Example We only have available the error message on the top of the stack. i.e. if (status) { /* If something went wrong, error message is at the top of */ /* the stack */ fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1)); /* I want to print a stacktrace here. How do I do that? */

How to create a traceback object

拜拜、爱过 提交于 2019-11-29 09:31:18
I want to create a traceback like the one returned by sys.exc_info()[2]. I don't want a list of lines, I want an actual traceback object: <traceback object at 0x7f6575c37e48> How can I do this? My goal is to have it include the current stack minus one frame, so it looks the the caller is the most recent call. abarnert There's no documented way to create traceback objects. None of the functions in the traceback module create them. You can of course access the type as types.TracebackType , but if you call its constructor you just get a TypeError: cannot create 'traceback' instances . The reason

Print an error message without printing a traceback and close the program when a condition is not met

若如初见. 提交于 2019-11-29 09:21:17
I've seen similar questions to this one but none of them really address the trackback. If I have a class like so class Stop_if_no_then(): def __init__(self, value one, operator, value_two, then, line_or_label, line_number): self._firstvalue = value_one self._secondvalue = value_two self._operator = operator self._gohere = line_or_label self._then = then self._line_number = line_number def execute(self, OtherClass): "code comparing the first two values and making changes etc" What I want my execute method to be able to do is if self._then is not equal to the string "THEN" (in allcaps) then I

How to get a complete exception stack trace in Python

╄→гoц情女王★ 提交于 2019-11-28 17:30:01
The following snippet: import traceback def a(): b() def b(): try: c() except: traceback.print_exc() def c(): assert False a() Produces this output: Traceback (most recent call last): File "test.py", line 8, in b c() File "test.py", line 13, in c assert False AssertionError What should I use if I want the complete stack trace including the call to a? If it matters I have Python 2.6.6 edit: What I'd like to get is the same information I'd get if I left the try except out and let the exception propagate to the top level. This snippet for example: def a(): b() def b(): c() def c(): assert False a

Get full traceback

淺唱寂寞╮ 提交于 2019-11-28 17:04:06
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: Dummy traceback.format_stack() is not what i want, as need traceback object to be passed to a third party module. I am particularly interested in this case: import logging def func(): try: raise Exception('Dummy') except: logging.exception("Something