5

我正在尝试在本地 Windows 机器上自动重新加载使用 apache + mod_wsgi 的 django 应用程序。

我想知道在哪里添加以下文章中引用的代码:

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

6 回答 6

5

读:

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

它会告诉您在使用 Django 时将文件放置在何处。您只需在与 Windows 相关的源代码重新加载文档部分中进行每个人都向您指出的代码更改。另请阅读:

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

这解释了第一个与 Windows 相关的变化。

于 2009-07-07T22:58:11.610 回答
1

我在我的服务器上使用此代码

touch site.wsgi

它工作。在浏览器中重新加载页面后,我得到了带有更改的页面。可能很难看 - 但简单且无需重新启动 apache。

于 2011-07-14T13:32:17.840 回答
1

您替换了同一篇文章中上述代码块中提到的重启功能。

于 2009-07-07T17:52:09.403 回答
0

您在页面上找到的以下代码块中替换了重新启动功能:

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)
于 2009-07-07T18:08:00.090 回答
0

我使用安装在D:\BitNami DjangoStackC:\Documents and Settings\tsurahman\BitNami DjangoStack projects\myproject作为项目目录的Bitnami DjangoStack http://bitnami.org/stack/djangostackWindows XP进行测试(默认安装)

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Apache_Processes中,我添加了

MaxRequestsPerChild 1

在文件D:\BitNami DjangoStack\apps\django\conf\django.conf 中,请参阅 Graham Dumpleton 的评论

然后我在我的项目目录中创建了一个文件monitor.py ,其内容如http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes并用http://code.google.com替换_restart方法/p/modwsgi/wiki/ReloadingSourceCode#Restarting_Windows_Apache,这是脚本的一部分

....

_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:

....

并在文件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()

然后重新启动 Apache 服务器

于 2011-08-04T12:17:09.480 回答
0

在您的虚拟主机配置文件中添加以下内容:

WSGIScriptReloading On

并重新加载 Apache

systemctl reload apache2

享受!

参考https://flask.palletsprojects.com/en/1.1.x/deploying/mod_wsgi/

于 2020-06-14T18:12:36.083 回答