This week I need to run a script with lot of calls to an API. Would be nice to do some requests in the begining to validate the feature, and then keep it running.

With Python Debugger, pdb, is really easy for this case. Let’s see and example:

for item in items:

Suppose items has a size of 10k. If you run this script with pdb, it will drop a shell, so just press c, to continue:

$ python -m pdb
> /private/tmp/<module>()
-> for item in items:
(Pdb) c

But, if you want to stop it, without quiting, you can press CTRL+C, which will drop you in the pdb shell, where you can continue to the next iteration, print variables, or resume typping:

Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /private/tmp/<module>()
-> for item in items:

This functionality was very useful, since I can stop now the script and resume. Was even able to stop the execution, close the laptop, open in another network and resume the script.