I owe all credit for knowing about this to this blog post. It's about the most useful thing I've ever seen since starting python a few years ago.
You can pip install ipython in your environment. Then, in the module you would like to debug:
from IPython.Shell import IPShellEmbed
ipython = IPShellEmbed()
Where you want to drop into the shell during execution:
ipython()
The program will hang at that point and give you an ipython prompt. You will have all of the local and global context of the suite from which you launch the shell, ready for inspection.
(via @wolever):
Put this in your pdbrc so you can drop into an ipy shell from PDB:
alias i from IPython.Shell import IPShellEmbed as IPSh; IPSh(argv='')()