Just a quick note for profiling e.g. Zope views:
class MyView(object): def __call__(self): result = {} cProfile.runctx('result["x"] = super(Body, self).__call__()', globals(), locals(), '/tmp/viewprofile') return result['x']
Even though “exec ‘result = super(…) in globals(), locals()’ works, it seems that cProfile does something a little differently here, so that writing to a local variable is not possible.