views:

372

answers:

3

So I'm trying to do more web development in python, and I've picked cherrypy, hosted by lighttpd w/ fastcgi. But my question is a very basic one: why do I need to restart lighttpd (or apache) every time I change my application code, or the code for an underlying library?

I realize this question extends from a basic mis(i.e. poor)understanding of the fastcgi model, so I'm open to any schooling here, but I'm used to just changing a PHP file and it showing up, versus having to bounce the web server.

Any elucidation/useful mockery appreciated.

A: 

Maybe auto-reload for CherryPy works. Have never tried it with fastcgi.

stephan
Note that this is a setting to the CherryPy *webserver*, not the framework.
Jason Baker
A: 

From a system-software-writer's pointer of view: This all depends on how the meta-data about the server process is organized within your daemon (lighttpd or fcgi). Some programs are designed for one time only initialization -- MOSTLY this allows a much simpler and better performing internal programming model.

Often it is very hard to program a server process reload config data in a easy way. You might have to introduce locks and external event objects (signals in UNIX). When you can synchronize the data structures by design -- i.e., only initializing once .... why complicate things by making the data model modifiable multiple times ?

Hassan Syed
+6  A: 

This is because of performance. For development, autoreloading is helpful. But for production, you don't want to autoreload. This is actually a decently-sized bottleneck in say PHP. Every time you access a PHP webpage, the server has to parse and load each page from scratch. With Python, the script is already loaded and running after the first access.

As has been pointed out, CherryPy has a autoreload setting. I'd recommend using the CherryPy built-in server for development and using lighttpd for production. That will likely save you some time. The tutorial shows you how to do this.

Jason Baker
Thanks- I am noticing a lot of comments upon a Googling that flup doesn't seem to work when cherrypy's auto reloading is on- any ideas there? I guess I could use a non-flup WSGI module.
Wells
Bear in mind that CherryPy is actually two components: a framework and server. If you're using lighttpd, then you're just using the framework. If you use the server in development, then you don't need to worry about this as it will autoreload automagically. Once you move to production, *then* I would switch to lighttpd.
Jason Baker