We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

sys.setprofile

setprofile(profilefunc)

Set the system’s profile function, which allows you to implement a Python source code profiler in Python. See chapter 10 for more information on the Python profiler. The system’s profile function is called similarly to the system’s trace function (see sys.settrace), but it isn’t called for each executed line of code (only on call and return, but the return event is reported even when an exception has been set). The function is thread-specific, but there is no way for the profiler to know about context switches between threads, so it does not make sense to use this in the presence of multiple threads. Also, its return value is not used, so it can simply return None.