3 ms·
I've shared this on here before, but another trick that I like with breakpoint() is to add this function to my Python projects so that I can drop into pdb by s
by senkora 2y ago
I've shared this on here before, but another trick that I like with breakpoint() is to add this function to my Python projects so that I can drop into pdb by sending a signal:
import signal
def sigusr1_handler(signum, stack):
breakpoint()
signal.signal(signal.SIGUSR1, sigusr1_handler)
And then I can drop into pdb by sending a signal:
$ kill -s sigusr1 $PID
It's especially useful for getting a backtrace out of your program when it's hanging, and poking around a bit to figure out why.
- misnome 2y agoIt doesn’t give you a debug repl, but my favourite tool for this sort of thing is py-spy; small and easy enough to install into a stuck pod’s ephemeral storage and and it can dump the stacktrace or give you a top-equivalent view on what your python process is doing. I was afraid it died as it didn’t get updated for python 3.12, but that’s thankfully apparently been solved now!
- randlet 2y agoNice trick!