python3 -B -m cProfile -s cumtime ./thescript.py
python3 -B -m pdb ./thescript.py
This will throw you into the debugger right from the start.
c<enter>
will run the script.
If it encounters an error, you will be back in the debugger and be able to examine local variables.
python3 -B -m pdb -c 'b some_module.py:123' ./thescript.py
pudb is a nicer experience than pdb. Put this where you want the debugger to kick in:
import pudb; pudb.set_trace();