I'm attempting to auto reload my django application which uses apache + mod_wsgi on my small local home windows machine.

Let me know where will i add this code that's recommended in this article:


def _restart(path):
    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



It informs you wherever to put the file when utilizing Django. You need to simply result in the code change that everybody is mentioning for you within the source code reloading documentation section associated with Home windows. Also read:


which describes the versions around the first associated with Home windows.

You replace the restart function that's pointed out within the block of code above within the same article.

You replace the restart function within the following block of code you discover around 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):
    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)

I personally use this code on my small server

touch site.wsgi

also it work. After reload page in browser I recieve page with changes. Might be it ugly - but easy and no necessary restart apache.