Long ago, I saw a C program that took another C program as input. It would output a copy of the original C program, interspersed with fprintf's that would display the text of the line current being executed.
You might write something similar for Python, perhaps outputting the line being executed and/or the line number. You could have it open a file in /tmp or something.
-- https://mail.python.org/mailman/listinfo/python-list