Apache Django Mod_Wsgi - Auto Reboot

I am trying to reload a django application that uses apache + mod_wsgi on my local windows machine.

I would like to know where to add this code specified in the following article:

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

def _restart(path): _queue.put(True) prefix = 'monitor (pid=%d):' % os.getpid() print >> sys.stderr, '%s Change detected to \'%s\'.' % (prefix, path) print >> sys.stderr, '%s Triggering Apache restart.' % prefix import ctypes ctypes.windll.libhttpd.ap_signal_parent(1) 
+4
source share
5 answers

Reading:

http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html

It tells you where to place the file when using Django. You just need to make changes to the code that everyone tells you in the documentation section for reloading Windows-related source code. Also read:

http://blog.dscpl.com.au/2009/02/source-code-reloading-with-modwsgi-on.html

which explains the first options related to Windows.

+5
source

You are replacing the restart function indicated in the code block above in the same article.

+1
source

You replace the restart function in the following block of code, which you will find on the page:

 Monitoring For Code Changes The use of signals to restart a daemon process could also be employed in a mechanism which automatically detects changes to any Python modules or dependent files. This could be achieved by creating a thread at startup which periodically looks to see if file timestamps have changed and trigger a restart if they have. Example code for such an automatic restart mechanism which is compatible with how mod_wsgi works is shown below. import os import sys import time import signal import threading import atexit import Queue _interval = 1.0 _times = {} _files = [] _running = False _queue = Queue.Queue() _lock = threading.Lock() def _restart(path): _queue.put(True) prefix = 'monitor (pid=%d):' % os.getpid() print >> sys.stderr, '%s Change detected to \'%s\'.' % (prefix, path) print >> sys.stderr, '%s Triggering process restart.' % prefix os.kill(os.getpid(), signal.SIGINT) 
0
source

I use this code on my server

 touch site.wsgi 

and it works. After reloading the page in the browser, I get the page with the changes. It may be ugly - but it just doesn’t need to restart apache.

0
source

I am testing this using Bitnami DjangoStack http://bitnami.org/stack/djangostack and Windows XP installed on D: \ BitNami DjangoStack and C: \ Documents and Settings \ tsurahman \ BitNami DjangoStack \ myproject projects as a project directory (installation by default)

as in http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Apache_Processes , I added

 MaxRequestsPerChild 1 

in file D: \ BitNami DjangoStack \ apps \ django \ conf \ django.conf see Graham Dumpleton's comment

then I created a monitor.py file in my project directory with content, as in http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes and replace the _restart method http://code.google.com/p / modwsgi / wiki / ReloadingSourceCode # Restarting_Windows_Apache , here is the script part

 .... _running = False _queue = Queue.Queue() _lock = threading.Lock() def _restart(path): _queue.put(True) prefix = 'monitor (pid=%d):' % os.getpid() print >> sys.stderr, '%s Change detected to \'%s\'.' % (prefix, path) print >> sys.stderr, '%s Triggering Apache restart.' % prefix import ctypes ctypes.windll.libhttpd.ap_signal_parent(1) def _modified(path): try: .... 

and in the file D: \ BitNami DjangoStack \ apps \ django \ scripts \ django.wsgi ,

 .... import django.core.handlers.wsgi import monitor monitor.start(interval=1.0) monitor.track(os.path.join(os.path.dirname(__file__), 'site.cf')) application = django.core.handlers.wsgi.WSGIHandler() 

and then restart the apache server

0
source

All Articles