{"id":8673,"date":"2015-02-13T21:46:02","date_gmt":"2015-02-13T21:46:02","guid":{"rendered":"https:\/\/wp.okra.host\/article\/using-wsgi\/"},"modified":"2021-03-07T14:44:11","modified_gmt":"2021-03-07T13:44:11","slug":"using-wsgi","status":"publish","type":"ht_kb","link":"https:\/\/kb.okra.host\/de\/article\/using-wsgi\/","title":{"rendered":"WSGI verwenden"},"content":{"rendered":"<h2 id=\"overview\" >Overview<\/h2>\n<p>Python applications can be launched using <a title=\"Using multiple versions with Passenger\" href=\"https:\/\/kb.okra.host\/python\/using-multiple-versions-passenger\/\">Passenger<\/a> offering improved throughput and lifecycle management. Launching CGI\u00a0scripts wrapped by\u00a0<code>pyenv<\/code> will yield very poor throughput as a result of multiple shell subprocesses necessary to ascertain the correct Python interpreter. Adapting a CGI\u00a0application to WSGI\u00a0improves throughput significantly by reducing overhead\u00a0through\u00a0a persistent process. Pages load quickly, and applications utilize resources efficiently.<\/p>\n<p><span style=\"color: #333399\"><strong>Note:<\/strong><\/span> This KB requires a <a title=\"Determining platform version\" href=\"https:\/\/kb.okra.host\/platform\/determining-platform-version\/\">v6+<\/a> hosting platform.<\/p>\n<h2 id=\"simple-wsgi-script\" >Simple WSGI script<\/h2>\n<p><span style=\"color: #333399\"><strong>Prerequisite<\/strong><\/span>: First, follow the guide in <a title=\"Using multiple versions with Passenger\" href=\"https:\/\/kb.okra.host\/python\/using-multiple-versions-passenger\/\">Using multiple versions with Passenger<\/a>\u00a0to create a suitable directory structure.<\/p>\n<p>Create a Passenger-compatible WSGI script named\u00a0<code>passenger_wsgi.py<\/code>\u00a0beneath the\u00a0<code>public\/<\/code> folder. A single function, similar to main() in a C application, named <code>application()<\/code>\u00a0is the entry-point for Passenger. Without this function and named file, Passenger cannot load your application.\u00a0The below example is compatible with Python 3:<\/p>\n<pre data-language=\"python\"><code># Python 3-compatible version\r\nimport sys\r\nctr=0\r\n\r\ndef application(environ, start_response):\r\n global ctr\r\n start_response('200 OK', [('Content-Type', 'text\/plain')])\r\n v = sys.version_info\r\n ctr+=1\r\n str = 'hello world from %d.%d.%d!n' % (v.major, v.minor, v.micro)\r\n return [bytes(str, 'UTF-8')]<\/code><\/pre>\n<p>Your directory structure should now look like:<\/p>\n<pre style=\"padding-left: 30px\">.\r\n\u251c\u2500\u2500 passenger_wsgi.py\r\n\u251c\u2500\u2500 public\/\r\n\u251c\u2500\u2500 .python-version\r\n\u2514\u2500\u2500 tmp\/<\/pre>\n<p><code>.python-version<\/code> is a file created by defining a Python version for the directory, e.g. <code>pyenv local 3.3.5<\/code>. Connect the <code>public\/<\/code> <a title=\"Where is site content served from?\" href=\"https:\/\/kb.okra.host\/web-content\/where-is-site-content-served-from\/\">folder<\/a> to a subdomain within the <a title=\"Logging into the control panel\" href=\"https:\/\/kb.okra.host\/control-panel\/logging-into-the-control-panel\/\">control panel<\/a> under <strong>Web<\/strong> &gt; <strong>Subdomains<\/strong>.<\/p>\n<h3 id=\"application-didnt-launch\" >Application didn&#8217;t launch?<\/h3>\n<p>Check the Passenger launcher <a title=\"Accessing web page views and error messages\" href=\"https:\/\/kb.okra.host\/web-content\/accessing-page-views-and-error-messages\/\">error log<\/a>\u00a0under <code>\/var\/log\/httpd\/passenger.log<\/code>. This is a combined logfile, so always remember to publish coherent, and flawless code!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Python applications can be launched using Passenger offering improved throughput and lifecycle management. Launching CGI\u00a0scripts wrapped by\u00a0pyenv will yield very poor throughput as a result of multiple shell subprocesses necessary to ascertain the correct Python interpreter. Adapting a CGI\u00a0application to WSGI\u00a0improves throughput significantly by reducing overhead\u00a0through\u00a0a persistent process. Pages&#8230;<\/p>","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[65],"ht-kb-tag":[],"class_list":["post-8673","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-python"],"_links":{"self":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/comments?post=8673"}],"version-history":[{"count":1,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8673\/revisions"}],"predecessor-version":[{"id":8674,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8673\/revisions\/8674"}],"wp:attachment":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/media?parent=8673"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-category?post=8673"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-tag?post=8673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}