{"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>\n

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.<\/p>\n","protected":false},"excerpt":{"rendered":"

Just a quick note for profiling e.g. Zope views: class MyView(object): \u00a0\u00a0\u00a0 def __call__(self): \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = {} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cProfile.runctx(‘result[“x”] = super(Body, self).__call__()’, \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’) \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 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 … Continue reading “Profiling class-based views”<\/span><\/a><\/p>\n","protected":false},"author":10315341,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[10221],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pFP3y-2b","jetpack-related-posts":[{"id":2890,"url":"https:\/\/blog.gocept.com\/2017\/10\/24\/zope4-errorhandling\/","url_meta":{"origin":135,"position":0},"title":"Catching and rendering exceptions","author":"Michael Howitz","date":"October 24, 2017","format":false,"excerpt":"Error handling in Zope 4","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1361,"url":"https:\/\/blog.gocept.com\/2013\/08\/28\/run-tests-using-layers-with-py-test\/","url_meta":{"origin":135,"position":1},"title":"Run tests using layers with py.test","author":"Michael Howitz","date":"August 28, 2013","format":false,"excerpt":"TL;DR Use gocept.pytestlayer. Long Story We have many test suites which use test layers (e. g. the ones from plone.testing). We want to use py.test\u00a0and all its fancy features to have a modern test runner. There was no way to convert such tests partly: either you have to port the\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2789,"url":"https:\/\/blog.gocept.com\/2017\/10\/25\/testing-zope-4beta2\/","url_meta":{"origin":135,"position":2},"title":"Migrating from Zope 2.13 to 4.0b2","author":"Michael Howitz","date":"October 25, 2017","format":false,"excerpt":"Beta-Testing Zope 4 together with PerFact Innovation","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26,"url":"https:\/\/blog.gocept.com\/2009\/11\/17\/localized-dates-with-zope-2-and-zope-3\/","url_meta":{"origin":135,"position":3},"title":"Localized dates with Zope 2 and Zope 3","author":"","date":"November 17, 2009","format":false,"excerpt":"Imagine, you want to display a date in a nicer way than just 2009-11-17. It's not that difficult to localize it into e.g. German and output 17.11.2009. But what, if you need to display\u00a0Mittwoch, 11.November 2009 instead? Calling\u00a0strftime('%A, %d.%B %Y') on your date object would format the date with month-\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":12,"url":"https:\/\/blog.gocept.com\/2009\/11\/24\/adding-round-corners-to-boxes-using-css-and-javascript\/","url_meta":{"origin":135,"position":4},"title":"Adding round corners to boxes using CSS and JavaScript","author":"","date":"November 24, 2009","format":false,"excerpt":"Curvycorners has a way to make gorgeous\u00a0roundings to your boxes without having to split each box into pieces of background images. You simply need to include one JavaScript file and add two lines of CSS code to your box (or to the box's class definition). First, include the curvycorners javascript\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1340,"url":"https:\/\/blog.gocept.com\/2013\/07\/31\/reproducable-automated-deployments-on-raspberrypi-with-batou\/","url_meta":{"origin":135,"position":5},"title":"Reproducable automated deployments on RaspberryPi with batou","author":"Daniel Havlik","date":"July 31, 2013","format":false,"excerpt":"For continuous integration during development, we use Jenkins to automatically run tests for all projects we maintain. Some time ago we wanted to increase visibility of the results, so we set up a Raspberry Pi driving a few meters of LPD8806-based LED strip on which we can address single LEDs\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/135"}],"collection":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/users\/10315341"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":3,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/135\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}