<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Michele Campeotto: Tag pylons</title>
    <link>http://blog.micampe.it/articles/tag/pylons?tag=pylons</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>I'm not Winston Wolfe.</description>
    <item>
      <title>A tale of Pylons, Python and FastCGI on Dreamhost</title>
      <description>&lt;p&gt;&lt;a href="http://pylonshq.com"&gt;Pylons&lt;/a&gt; is a &lt;a href="http://wsgi.org"&gt;WSGI&lt;/a&gt; based Python Web Framework that tries to combine the
best ideas from other existing frameworks and does so by glueing togheter
existing projects and allowing to swap its components at will and easily extend
its capabilites with other WSGI components.&lt;/p&gt;

&lt;p&gt;I will explain here how I installed it and a demo application on &lt;a href="http://www.dreamhost.com/r.cgi?195290"&gt;Dreamhost&lt;/a&gt;
and how to avoid the single problem I had.&lt;/p&gt;

&lt;p&gt;This procedure isn&amp;#8217;t specific to either Dreamhost or Pylons, it can be used
anywhere and for any WSGI compliant application if you don&amp;#8217;t have root access
to install new modules or if you want to keep the system wide installation
clean and add modules just for a single user.&lt;/p&gt;&lt;p&gt;The installation procedure is quite easy and mostly automated, start by running
these commands from your home directory on the remote shell:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mkdir bin
wget -P bin http://peak.telecommunity.com/dist/virtual-python.py
python2.4 bin/virtual-python
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It&amp;#8217;s important that you use &lt;code&gt;python2.4&lt;/code&gt; here, not just &lt;code&gt;python&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This command will create some directories and symlinks on your home directory
that will result in you little private Python environment, where you have the
power to install new packages at will. To make the illusion more real, you
should then add &lt;code&gt;~/bin&lt;/code&gt; in front of your &lt;code&gt;$PATH&lt;/code&gt;, so that you can just type
&lt;code&gt;python&lt;/code&gt; in the shell and the interpreter used will be your private one instead
of the global one.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;export PATH="~/bin:$PATH"    # add this to ~/.bash_profile
wget -P bin http://peak.telecommunity.com/dist/ez_setup.py
python bin/ez_setup.py
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will install the &lt;code&gt;easy_install&lt;/code&gt; script that you will use to install Pylons
and other Python modules you can find on the &lt;a href="http://cheeseshop.python.org/pypi"&gt;Cheese Shop&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;easy_install Pylons
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will install the Pylons framework and all its dependencies. To test the
installation we will use the &lt;a href="http://pylonshq.com/docs/quick_wiki.html"&gt;QuickWiki&lt;/a&gt; demo application:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;easy_install QuickWiki
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will install the application and some more dependencies. The next step is
creating the configuration file for the application:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;paster make-config QuickWiki wiki.ini
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this file you only have to change the database URI, for this test we will
use SQLite:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sqlalchemy.dburi = sqlite:///quickwiki.db
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And setup the application to create the database:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;paster setup-app wiki.ini
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then we need a script to start the application. Pylons, as every WSGI
application can be deployed in a number of different ways, but the only one you
can use on Dreamhost is FastCGI. At this point, every tutorial around the web
will tell you to use &lt;a href="http://www.saddi.com/software/flup/"&gt;flup&lt;/a&gt; and then there will be pain and hair pulling
because you won&amp;#8217;t understand why it&amp;#8217;s not working (unless you ask &lt;a href="http://blogs.flup.org/page/asaddi"&gt;Allan
Saddi&lt;/a&gt; to check your setup, that is. Thank you Allan!).&lt;/p&gt;

&lt;p&gt;The solution is to use the supposed to be obsolete &lt;a href="http://svn.saddi.com/py-lib/trunk/fcgi.py"&gt;fcgi.py&lt;/a&gt; script, so let&amp;#8217;s
install it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;wget -P lib/python2.4/site-packages http://svn.saddi.com/py-lib/trunk/fcgi.py
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We said we needed a script, so put this in a file named &lt;code&gt;server.fcgi&lt;/code&gt; in your
web directory and make it executable:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/home/username/bin/python

from paste.deploy import loadapp
from fcgi import WSGIServer

app = loadapp('config:/home/username/www.yourdomain.net/wiki.ini')
server = WSGIServer(app)
server.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You will need to correct the paths here, as we need them to be absolute.&lt;/p&gt;

&lt;p&gt;Now when you point at this file in a web browser you should see the QuickWiki
FrontPage.&lt;/p&gt;

&lt;p&gt;The problem with flup (as found by Allan itself) is that it takes too long to start and it seems that FastCGI on Dreamhost will wait for a maximum of 3 seconds. &lt;code&gt;fcgi.py&lt;/code&gt; instead is simpler (doesn&amp;#8217;t do thread pooling for example) and therefore faster to start. This means that when the server is under heavy load there could still be problems, but it has been pretty reliable.&lt;/p&gt;

&lt;p&gt;The best solution to this problem would be &lt;a href="http://www.mems-exchange.org/software/scgi/"&gt;SCGI&lt;/a&gt; support by Dreamhost, if you already are a customer, go &lt;a href="https://panel.dreamhost.com/index.cgi?tree=home.sugg&amp;amp;search=scgi"&gt;vote for it&lt;/a&gt;!&lt;/p&gt;</description>
      <pubDate>Sun, 26 Nov 2006 08:01:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:8a140a5f-4804-415f-91f2-b2bd554b87af</guid>
      <author>micampe</author>
      <link>http://blog.micampe.it/articles/2006/11/26/a-tale-of-pylons-python-and-fastcgi-on-dreamhost</link>
      <category>English</category>
      <category>python</category>
      <category>pylons</category>
      <category>wsgi</category>
      <category>fastcgi</category>
      <category>dreamhost</category>
      <category>django</category>
      <category>turbogears</category>
      <trackback:ping>http://blog.micampe.it/articles/trackback/1067</trackback:ping>
    </item>
  </channel>
</rss>
