Running the risk of not answering the actual question, you wrote that you need it for research and debugging.
I think the traceback
module is just great for that.
import traceback
traceback.print_stack()
Also take a look at pdb
, it allows you to interactively step through your code during runtime.