Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?

Just to make it clear, since I see some people get it wrong, I'm talking about a production environment. For development I'm using Django's development server, of course.

share|improve this question

4 Answers 4

up vote 15 down vote accepted

If possible, you should switch to mod_wsgi. This is now the recommended way to serve Django anyway, and is much more efficient in terms of memory and server resources.

In mod_wsgi, each site has a .wsgi file associated with it. To restart a site, just touch the relevant file, and only that code will be reloaded.

share|improve this answer
    
I'm a bit scared of this XXgi things after all the trouble I had with FastCGI (sure, it was Lighttpd, but still): stackoverflow.com/questions/393637/…. Didn't know wsgi is the recommended way to deploy Django now. It used to be mod_python, right? Anyway, I'll look into it. Thanks! – ibz Jul 3 '09 at 10:12
    
s/this things/these things/ :) – ibz Jul 3 '09 at 10:13
2  
As noted elsewhere, you must use mod_wsgi daemon mode to get feature whereby a reload will occur when WSGI script file is touched. – Graham Dumpleton Jul 3 '09 at 10:20
    
@ibz: mod_wsgi is so different from fastcgi that they are not comparable in any way. – S.Lott Jul 3 '09 at 12:14
1  
Note that (as Graham Dumpleton mentions below) the touch-.wsgi-file-to-restart only works in daemon mode, not embedded mode. – Carl Meyer Jul 3 '09 at 21:13

As others have suggested, use mod_wsgi instead. To get the ability for automatic reloading, through touching the WSGI script file, or through a monitor that looks for code changes, you must be using daemon mode on UNIX. A slight of hand can be used to achieve same on Windows when using embedded mode. All the details can be found in:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

share|improve this answer

You can reduce number of connections to 1 by setting "MaxRequestsPerChild 1" in your httpd.conf file. But do it only on test server, not production.

or

If you don't want to kill existing connections and still restart apache you can restart it "gracefully" by performing "apache2ctl gracefully" - all existing connections will be allowed to complete.

share|improve this answer
    
"apache2ctl gracefully" sounds like a neat thing. Will definitely look into that, even though it's not exactly what I was looking for. Thanks for the tip! – ibz Jul 3 '09 at 10:10

Use a test server included in Django. (like ./manage.py runserver 0.0.0.0:8080) It will do most things you would need during development. The only drawback is that it cannot handle simultaneous requests with multi-threading.

I've heard that there is a trick that setting Apache's max instances to 1 so that every code change is reflected immediately--but because you said you're running other services, so this may not be your case.

share|improve this answer
    
Thats "MaxRequestsPerChild 1" set in httpd.conf as told by zdmytriv, but DO NOT do this for site handling any load. – agiliq Jul 3 '09 at 9:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.