Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 带有wsgi的Django偶尔会出现故障;脚本标题过早结束:“引用”;_Python_Django_Mod Wsgi - Fatal编程技术网

Python 带有wsgi的Django偶尔会出现故障;脚本标题过早结束:“引用”;

Python 带有wsgi的Django偶尔会出现故障;脚本标题过早结束:“引用”;,python,django,mod-wsgi,Python,Django,Mod Wsgi,我有一个网站在Apache2上运行了几个月,定期会出现以下问题: [Sat Nov 12 06:18:34 2011] [error] [client X.Y.Z.158] Premature end of script headers: sleepsoundly_wsgi.py [Sat Nov 12 06:18:49 2011] [error] [client X.Y.Z.158] Premature end of script headers: sleepsoundly_wsgi.py

我有一个网站在Apache2上运行了几个月,定期会出现以下问题:

[Sat Nov 12 06:18:34 2011] [error] [client X.Y.Z.158] Premature end of script headers: sleepsoundly_wsgi.py
[Sat Nov 12 06:18:49 2011] [error] [client X.Y.Z.158] Premature end of script headers: sleepsoundly_wsgi.py
它已经运行了1000个请求,没有任何问题,但它会定期执行几次,然后一切都会正常。这是在上载大约300个文件时发生的(每个文件(.5 MB)。每个文件单独上传,一次上传3个文件,225个文件上传正常,226和227个文件上传失败,然后228->end都正常工作。它并不是每次都这样做,只是偶尔会这样做,而且这些文件也不总是会失败。另一次,文件291失败,其余的都正常工作

除了这条隐秘的信息,我在日志里没有什么要说的

我已经检查过了,机器上唯一的python版本是2.7.1。我没有收到django的电子邮件,我没有任何关于可能发生的事情的正常线索。我很好奇如何开始解决这个问题。它可以自行恢复,上传文件的自动程序会不断移动。我怎么知道这件事是怎么回事

Server version: Apache/2.2.17 (Ubuntu)
Server built:   Sep  1 2011 09:25:26
mod_wsgi: Version: 3.3-2ubuntu2

Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)

wsgi.conf has no lines in it that are not commented out.

VirtualHost setup:
    WSGIDaemonProcess myemr user=mjones processes=1 maximum-requests=500 threads=15
    WSGIProcessGroup  myemr
    WSGIScriptAlias   / /var/www/Python/myemr/myemr/deploy/myemr_wsgi.py

myemr_wsgi.py
    from os.path import abspath, dirname, join
    import sys

    # For packages that don't play well with mod_wsgi
    sys.stdout = sys.stderr

    sys.path.insert(0, abspath(join(dirname(__file__), "../..")))
    sys.path.insert(0, abspath(join(dirname(__file__), "../../myemr")))
    sys.path.insert(0, abspath(join(dirname(__file__), "../../myemr/apps")))
    sys.path.insert(0, abspath(join(dirname(__file__), "../../lib/python2.7/site-packages/")))

    # We have to add both of these because they are  installed with git?
    sys.path.insert(0, abspath(join(dirname(__file__), "../../src/pinax/")))

    from django.core.handlers.wsgi import WSGIHandler
    import pinax.env

    # setup the environment for Django and Pinax
    pinax.env.setup_environ(project_path='myemr')

    # set application for WSGI processing
    application = WSGIHandler()

问题可能是因为“最大请求数”设置为500。这将导致mod_wsgi守护进程定期重新启动。由于mod_wsgi守护进程是以多线程配置运行的,因此,如果在重新启动时有一个卡住的请求,或者长时间运行的请求在强制关闭超时之前没有完成,那么它将由于进程重新启动而中止。Apache子工作进程随后会将其视为一个请求终止,而不返回包含您看到的消息的头

故事的寓意是,不要在生产系统中使用“最大请求”选项,除非您有一个很好的理由,比如内存增长失控

mod_wsgi的4.0版本将有一个可选的但稍微更优雅的重启选项,可用于这种情况,但它仍然不能永远等待,卡住的请求仍将在某个点被中止,您仍将看到消息


顺便说一句,不要指定“processs=1”,因为它默认为一个进程,任何使用“processs”选项(即使值为“1”)都会将“wsgi.multiprocess”设置为True。“processes=1”的使用应该只在有一个进程且有多个Apache实例的情况下进行,这些实例都是通过一个进程进行负载平衡的。

您确定主Apache错误日志中没有“Segmentation fault”消息吗?还提供您正在使用的WSGIDaemonProcess配置,并指出是否有任何机制用于定期优雅地重新启动Apache。添加了我的配置。想知道
线程:no
选项是否就是问题所在。。。。。直到我开始尝试记录这个问题,我才意识到这一点。我已经检查了所有日志,“egmenation”没有出现在任何地方。