views:

69

answers:

2

I have a website that right now, runs by creating static html pages from a cron job that runs nightly.

I'd like to add some search and filtering features using a CGI type script, but my script will have enough of a startup time (maybe a few seconds?) that I'd like it to stay resident and serve multiple requests.

This is a side-project I'm doing for fun, and it's not going to be super complex. I don't mind using something like Pylons, but I don't feel like I need or want an ORM layer.

What would be a reasonable approach here?

EDIT: I wanted to point out that for the load I'm expecting and processing I need to do on a request, I'm confident that a single python script in a single process could handle all requests without any slowdowns, especially since my dataset would be memory-resident.

+4  A: 

That's exactly what WSGI is for ;)

I don't know off hand what the simplest way to turn a CGI script into a WSGI application is, though (I've always had that managed by a framework). It shouldn't be too tricky, though.

That said, An Introduction to the Python Web Server Gateway Interface (WSGI) seems to be a reasonable introduction, and you'll also want to take a look at mod_wsgi (assuming you're using Apache…)

David Wolever
The thing that struck me about WSGI, as I was reading about it, was that it wasn't really intended to be used by "end-users" like this; it was more like an interface between other frameworks and the web server. Anyone here tried using WSGI directly? Is it usable?
csbrooks
writing in wsgi I would consider easier than writing a straight cgi. If you use Webob it's even easier.
Tom Willis
Ok, WSGI looks like the way to go here. Thanks!This link (one of the links above) sealed it for me:http://bitworking.org/news/Why_so_many_Python_web_frameworks
csbrooks
Or, use werkzeug. Or use almost any web framework. They're all easier than messing with CGI.
S.Lott
@S.Lott: Can't say I agree with that. There's a certain simplicity in being able to just print out some HTTP headers and HTML, compared to setting up models, views, controllers, templates, databases, and so on.
Kylotan
I agree with @S.Lott – learning a simple framework is well worth the time invested, even if you won't use it very often. When I picked it up a couple years ago, web.py (http://webpy.org/) was very simple, and I've heard good things about Werkzeug too.
David Wolever
A: 

maybe you should direct your search towards inter process commmunication and make a search process that returns the results to the web server. This search process will be running all the time assuming you have your own server.

Esben Skov Pedersen
No, I'd say this is the wrong way to do it. IPC is tricky and that's almost what WSGI already does: when `mod_wsgi` starts, it `fork()`s and starts a process to run your script, then when Apache gets a request for a URL which serves your script, that request gets handed to `mod_wsgi` which then hands it to your script. All pretty much transparent to you.
David Wolever
@david you are of course right. I don't know how WSGI works, but op didn't like it so I was trying to find an anternative solution.
Esben Skov Pedersen