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:
    requests.get(url=API/item,....)

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 script.py
> /private/tmp/script.py(1)<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:

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

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.