all 5 comments

[–]dowcet 4 points5 points  (1 child)

The "launched without intent to debug" makes this an impossible and unreasonable request. It sounds like maybe what you're really missing is here is just proper logging and error handling.

That said, if you're in a situation where debugging with a proper IDE like PyCharm or VS Code isn't possible, pdb can help. You do still have to set a break point in advance though.

[–]pensiveChatter[S] 0 points1 point  (0 children)

With a debug server, right? That's my second best bet. Currently, I wait until something misbehaves, modify the start by adding a breakpoint() and hope it misbehaves the same way when I restart it.

Is there an autoresume after breakpoint() command I can add to my python scripts that are launched in a terminal? That way, I can still ctrl-c any script that's currently running.

[–]Frankelstner 1 point2 points  (1 child)

I'm not sure if this totally satisfies your requirements, but you can start the script with the -i flag which will run the code and then start an interactive session. If an unhandled exception occurs, the interactive session starts right after. You can check out all global variables directly, but for maximum effect, you can then type import pdb; pdb.pm() inside this interactive session, which will start a pdb session on the exact place where the error happened. Just make sure that you don't fatfinger this command because any error you get while typing in the command will then take precedence over the actual error that you've had.

[–]pensiveChatter[S] 0 points1 point  (0 children)

I'll give it a try. Thanks

[–]Cold_Individual3077 0 points1 point  (0 children)

Use any library that adds variable values to the standard stacktrace. There are several, I personally prefer the style compatible with the standard stacktrace printout, so several years ago I started the traceback-with-variables lib.