{"id":135,"date":"2012-04-03T14:15:38","date_gmt":"2012-04-03T12:15:38","guid":{"rendered":"http:\/\/blog.gocept.com\/?p=135"},"modified":"2012-12-03T15:08:29","modified_gmt":"2012-12-03T14:08:29","slug":"profiling-class-based-views","status":"publish","type":"post","link":"https:\/\/blog.gocept.com\/2012\/04\/03\/profiling-class-based-views\/","title":{"rendered":"Profiling class-based views"},"content":{"rendered":"
Just a quick note for profiling e.g. Zope views:<\/p>\n
class MyView(object):\r\n\u00a0\u00a0\u00a0 def __call__(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = {}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cProfile.runctx('result[\"x\"] = super(Body, self).__call__()',\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 globals(), locals(), '\/tmp\/viewprofile')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return result['x']<\/pre>\nEven 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.<\/p>\n","protected":false},"excerpt":{"rendered":"