Re:Local Variables as Accidental Breadcrumbs for Faster Debu...
by aidos on Thursday October 10, 2024 @02:13PM
(#41801586)
I love debugging Python. The stacktraces are great when logged through Sentry so even on production I can normally spot the bug immediately.
On my local machine it’s even better because I can run the code, let it break and then jump straight into the debugger where I can move up and down through the stack. I can sit in the context at any point and play with the data. I can call any Python function I want to see how the code behaves.
Re:Local Variables as Accidental Breadcrumbs for Faster Debu...
by vanschelven on Thursday October 10, 2024 @04:57PM
(#41803526)
> The stacktraces are great when logged through Sentry
<cough>Bugsink</cough> :-)
Re:Local Variables as Accidental Breadcrumbs for Faster Debu...
by nomel on Thursday October 10, 2024 @03:18PM
(#41802423)
I don't think it's related to being a dynamic language. There are many "pretty exception printers" that will dump all the local and global variables, if you want.
Re:Local Variables as Accidental Breadcrumbs for Faster Debu...
by saila on Thursday October 10, 2024 @04:34PM
(#41803282)
I don't think Python is special in this regard. I have the same issue with .NET/C# stack traces.
With Python, you can run your program under pdb, which will automatically enter break on exceptions, and you can easily print locals.
Re:Local Variables as Accidental Breadcrumbs for Faster Debu...
by Sohcahtoa82 on Thursday October 10, 2024 @07:01PM
(#41804444)
> What’s the easiest possible way to cause stacktraces to also dump local variable information? I feel like this is a feature that should be built into the language…
That is built into Python!
import sys
def div(x, y):
return x / y
try:
print(div(1, 0))
except ZeroDivisionError as e:
print("Div by zero!")
print("Locals:")
_, _, tb = sys.exc_info()
print(tb.tb_next.tb_frame.f_locals)
This will output: Div by zero!
Locals:
{'x': 1, 'y': 0}
https://stackoverflow.com/a/5328139 has a more thorough implementation that will print you entire stack of local variables.
Re:Local Variables as Accidental Breadcrumbs for Faster Debu...
by NoGravitas on Thursday October 10, 2024 @08:09PM
(#41804856)
I don't think it's intrinsic to dynamic languages. I've been reading this from a Common Lisp perspective and all I can think of is, "look what they need to mimic a fraction of our power".
What’s the easiest possible way to cause stacktraces to also dump local variable information? I feel like this is a feature that should be built into the language…