These patches are the result of work that we have done in profiling Stackless Python server applications at runtime, but they apply just as well to C Python.The first patch makes _lsprof, the engine behind cProfile, multi-stack aware. This allows the same cProfiler.Profile() instance to be active on multiple python threads and still meaningful information is gathered.
The second patch allows to set the trace/profile function in python globally, so that all threads are affected. This is essential if you want to take a profililng snapshot of a running application.