Newbie question - using cgi to serve my app

0 views
Skip to first unread message

Rudy

unread,
May 2, 2008, 12:47:07 PM5/2/08
to pylons-discuss
Hello,
I'm new to this framework, so pardon my ignorance, but here goes:
I've spent a LOT of time trying to get this working on my server, and
now I have some specific questions:

I have gotten a project up and running, and I can verify it by
starting the paster server, and then running a lynx webserver to
localhost:5000. This shows I am getting the proper 'hello world'
controller working (and the route that directs to the hello controller
from the root url).

However, I am still stuck on how to get the public to view my site,
given that I am on a server without root privileges, and the Apache
install does not have mod_python, mod_wsgi, or mod_fcgi. I do have
mod_proxy, but I'm not clear how I can use that to serve my pages. I
suppose I could redirect certain urls to point to the port 5000 paster
server

I found an article on how to use straight CGI to serve a WSGI
application, and I got it working for static pages, by putting this
script (called test.py) in my cgi-bin directory:
#!/usr/home/rgamage/bin/python

from paste.deploy import loadapp
wsgi_app = loadapp('config:/usr/home/rgamage/siv/siv_production.ini')
import wsgiref.handlers
wsgiref.handlers.CGIHandler().run(wsgi_app)

If I have a static index.html in the public directory, then this
method works - going to http://mywebspace.com/cgi-bin/test.py yields
the proper static welcome page. However, if I delete that index.html,
I expect it to run the sample controller, hello, and instead I get
this series of exceptions:

Output of script follows:
=====================================================
Traceback (most recent call last):
File "/usr/local/lib/python2.5/wsgiref/handlers.py", line 92, in run
self.result = application(self.environ, self.start_response)
File "/usr/home/rgamage/lib/python2.5/site-packages/Paste-1.4.2-
py2.5.egg/paste/cascade.py", line 92, in __call__
return self.apps[-1](environ, start_response)
File "/usr/home/rgamage/lib/python2.5/site-packages/Paste-1.4.2-
py2.5.egg/paste/registry.py", line 340, in __call__
app_iter = self.application(environ, start_response)
File "/usr/home/rgamage/lib/python2.5/site-packages/Paste-1.4.2-
py2.5.egg/paste/recursive.py", line 80, in __call__
return self.application(environ, start_response)
File "/usr/home/rgamage/lib/python2.5/site-packages/Paste-1.4.2-
py2.5.egg/paste/errordocument.py", line 185, in __call__
app_iter = self.application(environ, change_response)
File "/usr/home/rgamage/lib/python2.5/site-packages/Paste-1.4.2-
py2.5.egg/paste/evalexception/middleware.py", line 180, in __call__
"The EvalException middleware is not usable in a "
AssertionError: The EvalException middleware is not usable in a multi-
process environment
Status: 500 Dude, this is whack!
Content-Type: text/plain
Content-Length: 59

A server error occurred. Please contact the administrator.

Any ideas you guys have would be much appreciated. Also, I don't
quite understand how I would reference different controllers using the
cgi method. The test.py script runs my application, but how would I
specify which controller or page within the app? Is this method even
a good idea, or should I make the jump to another hosting service that
provides mod_python or mod_wsgi?

Thanks,
Randy

Luis Bruno

unread,
May 2, 2008, 12:58:18 PM5/2/08
to pylons-...@googlegroups.com
Rudy escreveu:

> I do have mod_proxy, but I'm not clear how I can use that to serve my pages. I
> suppose I could redirect certain urls to point to the port 5000 paster server
>

That would be probably a better idea than CGI. Pylons has a big startup
cost; it's better to pay it once than on each request.

I vaguely remember some gotchas, but Ian Bicking wrote some middleware
to handle it. Ah, someone else went to the trouble of documenting it
(thank James Gardnet and Ben Bangert):
http://wiki.pylonshq.com/display/pylonscookbook/Apache+as+a+reverse+proxy+for+Pylons

> AssertionError: The EvalException middleware is not usable in a multi-
> process environment
>

"Clearly" labeled. Edit the load_middleware function IIRC and have a
look around, if you want to explore CGI a bit more deeply.


Hope that helps,
--lbruno

signature.asc

Rudy

unread,
May 2, 2008, 1:55:40 PM5/2/08
to pylons-discuss
Thanks for the reply. The only trouble with redirecting to the paster
server is that I don't know if I can leave the paster running after I
log out. Right now, I have to log in and start the paster server,
then start another login window and run lynx to test the server. When
I log out the process gets killed. I can start it as a backround
task, but I think it will still be killed when I log out.

Thanks,
Randy

On May 2, 9:58 am, Luis Bruno <m...@lbruno.org> wrote:
> Rudy escreveu:
>
> > I do have mod_proxy, but I'm not clear how I can use that to serve my pages. I
> > suppose I could redirect certain urls to point to the port 5000 paster server
>
> That would be probably a better idea than CGI. Pylons has a big startup
> cost; it's better to pay it once than on each request.
>
> I vaguely remember some gotchas, but Ian Bicking wrote some middleware
> to handle it. Ah, someone else went to the trouble of documenting it
> (thank James Gardnet and Ben Bangert):http://wiki.pylonshq.com/display/pylonscookbook/Apache+as+a+reverse+p...
>
> > AssertionError: The EvalException middleware is not usable in a multi-
> > process environment
>
> "Clearly" labeled. Edit the load_middleware function IIRC and have a
> look around, if you want to explore CGI a bit more deeply.
>
> Hope that helps,
> --lbruno
>
> signature.asc
> 1KDownload

kai

unread,
May 2, 2008, 2:01:04 PM5/2/08
to pylons-...@googlegroups.com
can you launch the paster server from within screen?
That is how I do it when developing then when I go production
I use daemontools to monitor it

Cliff Wells

unread,
May 2, 2008, 3:32:21 PM5/2/08
to pylons-...@googlegroups.com

On Fri, 2008-05-02 at 10:55 -0700, Rudy wrote:
> Thanks for the reply. The only trouble with redirecting to the paster
> server is that I don't know if I can leave the paster running after I
> log out. Right now, I have to log in and start the paster server,
> then start another login window and run lynx to test the server. When
> I log out the process gets killed. I can start it as a backround
> task, but I think it will still be killed when I log out.

There's several utilities for managing this (screen, dtach, etc), but
the good old-fashioned way is "nohup":

$ nohup paster serve myapp.cfg

Regards,
Cliff


Reply all
Reply to author
Forward
0 new messages