Apache Django Mod_Wsgi - auto reload

后端 未结 6 633
执念已碎
执念已碎 2020-12-29 15:54

I am trying to auto reload my django app which uses apache + mod_wsgi on my local windows machine.

I\'d like to know where do I add this code that\'s referenced in

6条回答
  •  北海茫月
    2020-12-29 16:54

    You replace the restart function in the following block of code you 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)
    

提交回复
热议问题