How to get stack trace string without raising exception in python?
It's traceback.extract_stack()
if you want convenient access to module and function names and line numbers, or ''.join(traceback.format_stack())
if you just want a string that looks like the traceback.print_stack()
output.