Elektrine lite

← Feed

@encthenet@flyovercountry.social

Post #2513084

2026-05-14 00:27 UTC

A couple go to Python debugging aids of mine, first is breaking into the debugger. import pdb; pdb.set_trace() The second is: ``` def printtb(fun): import functools @functools.wraps(fun) def wrapper(*a, **kwa): try: return fun(*a, *kwa) except: import traceback; traceback.print_exc() raise return wrapper ``` Then any functions that is throwing an exception that I can't easily wrap elsewhere (or have no clue where it's being called from), I just throw this wrapper around it and I get the traceback I need. #Python

Replies (4)

  • @glyph@mastodon.social 2026-05-14 01:41

    @encthenet@flyovercountry.social I think you want https://docs.python.org/3/library/traceback.html#traceback.print_stack not print_exc

    Open ##2971422

  • @diazona@techhub.social 2026-05-14 02:01

    @encthenet@flyovercountry.social Nice 😀 For the first one, I think the breakpoint() function would do the same thing? #Python

    Open ##2971427

  • @jonny@neuromatch.social 2026-05-14 02:05

    @encthenet@flyovercountry.social check out python -m pdb -c continue ./something.py or pdb.post_mortem :)

    Open ##2971430

  • @encthenet@flyovercountry.social > go to Python debugging aids Yes please let us push out the word Have you next thought about getting more people to adopt Python's breakpoint() pass pdb.pm() ? 2018 Python 3.7 gave us breakpoint, and I've got people to call it, and more lately you don't even have to add the Pass statement afterwards to make it work well The Post-Mortem Debugger at pdb.pm() I have trouble getting people to appreciate I dunno how to deploy it well myself in less than like 50 Lines of patch, as attached => https://github.com/pelavarre/pylitfun/blob/main/bin/litpython.py#L530

    Open ##2971432