共享主机中的Python内存错误
#!/home/<username>/bin/python
import os, sys
sys.path.insert(0, "/home/<username>/djangoprojects")
sys.path.insert(0, "/home/<username>/djangoprojects/testproject")
os.environ['PATH']= "/home/<username>/bin:"+os.environ['PATH']
os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
我在一个共享的网络主机上尝试部署django,但这个主机并不是专门为django设计的。这个主机上安装的是旧版的python,不过因为我有ssh访问权限,所以我在自己的主目录里安装了需要的模块(包括django),扩展了python的功能。
我创建了django项目,做了一些必要的调整(比如设置PYTHONPATH和PATH等环境变量),还写了一个django.fcgi脚本来启动django,然后在命令行里运行了./django.fcgi。
这是我得到的反馈:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Traceback (most recent call last):
File "/home/tentacle/lib/python2.4/site-packages/flup-1.0.3.dev_20110405-py2.4.egg/flup/server/fcgi_base.py", line 574, in run
protocolStatus, appStatus = self.server.handler(self)
File "/home/tentacle/lib/python2.4/site-packages/flup-1.0.3.dev_20110405-py2.4.egg/flup/server/fcgi_base.py", line 1159, in handler
result = self.application(environ, start_response)
File "/home/tentacle/lib/python2.4/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/home/tentacle/lib/python2.4/site-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/home/tentacle/lib/python2.4/site-packages/django/core/handlers/base.py", line 202, in handle_uncaught_exception
from django.views import debug
File "/home/tentacle/lib/python2.4/site-packages/django/views/debug.py", line 9, in <module>
from django.template import (Template, Context, TemplateDoesNotExist,
File "/home/tentacle/lib/python2.4/site-packages/django/template/__init__.py", line 53, in <module>
from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END,
MemoryError
Status: 500 Internal Server Error
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>Unhandled Exception</title>
</head><body>
<h1>Unhandled Exception</h1>
<p>An unhandled exception was thrown by the application.</p>
</body></html>
我知道这个问题可能是因为我用户的内存限制(对吗?),但是难道真的低到连基本的django都无法运行吗?更糟糕的是,一个月前同样的服务商给了我一个测试账户,我不仅能运行django,还能在本地安装更新版的python,并且运行得很好。
我向我的网络主机支持团队寻求帮助,但没有得到任何有用的答案。而且因为他们是转售商,我也不太确定他们能提供多少帮助。
有没有办法解决这个问题?欢迎任何建议。
谢谢大家的帮助。
-----------------------------------更新--------------------------------------------------
这是我的配置情况。我必须承认有一个小错误(解释器路径),但'settings'文件的路径是正确的。
在把解释器路径改正后,第一次运行时我遇到了StringError(django某个文件中的三重引号文档字符串没有关闭 - 嗯,这有点难),然后在下一次运行时出现了MemoryError,接着又是MemoryError,如此反复。过了一段时间(大约一个小时),我再次尝试执行脚本(没有做进一步的更改),结果不断出现Segmentation fault (core dumped)。
有什么建议吗?
1 个回答
当你从命令行运行这个程序时,需要明确地指定Django的一些参数。假设你是在和你的 settings.py
文件在同一个文件夹里运行这个脚本:
import os, sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
# ... rest of your startup script...
另外,检查一下你的 .htaccess
文件,看看里面的 RewriteRule
是否仍然正确指向你的 .fcgi
脚本。