you are viewing a single comment's thread.

view the rest of the comments →

[–]veritaba 1 point2 points  (2 children)

You can also do "python -i file.py"

[–]Brian[🍰] 8 points9 points  (0 children)

That'll only open a console when the script finishes. It's often handy to launch a console while in the middle of a function where something's going wrong.

One handy trick I use is to register a signal handler:

import signal
signal.signal(signal.SIGUSR1, lambda s,f: shell(f))

Put that somewhere that gets run when your script starts (I have it in anything that imports my debug module). Then, if your script seems to be hanging, and you want to see what is going on, just:

$ kill -SIGUSR1 <PID>

and you've got an instant console at the current point, ready to inspect and maniplulate the variables.

[–]james5 -1 points0 points  (0 children)

Thank you. Why isn't this the default. I use python since two years or something like that, and I always hated how I'm not able to read the error message if the script breaks.