namespace = frame.f_globals.copy()
namespace.update(frame.f_locals)
print('START DEBUG')
code.interact(banner=banner, local=namespace)
print('END DEBUG')
How can I start the python console within a program (for easy debugging)?