{"id":3832,"date":"2014-03-30T05:56:54","date_gmt":"2014-03-30T05:56:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-handle-local-long-living-objects-in-wsgi-env-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:56:54","modified_gmt":"2014-03-30T05:56:54","slug":"how-to-handle-local-long-living-objects-in-wsgi-env-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-handle-local-long-living-objects-in-wsgi-env-collection-of-common-programming-errors\/","title":{"rendered":"How to handle local long-living objects in WSGI env-Collection of common programming errors"},"content":{"rendered":"<p>WSGI is merely a standardized interface that makes it possible to build the various components of a web-server architecture so that they can talk to each other.<\/p>\n<p>Pyramid is a framework whose components are glued with each other through WSGI.<\/p>\n<p>Pyramid, like other WSGI frameworks, makes it possible to choose the actual <em>server<\/em> part of the stack, like gunicorn, Apache, or others. That choice is for you to make, and there lies the ultimate answer to your question.<\/p>\n<p>What you need to know is whether your server is multi-threaded or multi-process. In the latter case, it&#8217;s not enough to check whether a global variable has been instantiated in order to initialize costly resources, because subsequent requests might end up in separate processes, that don&#8217;t share state.<\/p>\n<p>If your model is multi-threaded, then you might indeed rely on global state, but be aware of the fact that you are introducing a strong dependency in your code. Maybe a singleton pattern coupled with dependency-injection can help to keep your code cleaner and more open to change.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WSGI is merely a standardized interface that makes it possible to build the various components of a web-server architecture so that they can talk to each other. Pyramid is a framework whose components are glued with each other through WSGI. Pyramid, like other WSGI frameworks, makes it possible to choose the actual server part of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3832","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3832"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3832\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}