共享主机中的python MemoryError

标签 python django shared-hosting shared-memory

我试图在一个非 Django 特定的共享虚拟主机上部署 Django。 Host 提供旧版本的 python 安装,但由于我有 ssh 访问能力,我设法通过在我的主文件夹中本地安装它们来使用我需要的模块(包括 django)扩展 python 安装。 好的,所以我创建了 django 项目,做了需要做的调整(设置 PYTHONPATH 和 PATH 全局变量等),制作了启动 django 的 django.fcgi 脚本,并从 shell 执行 ./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 并运行得很好。 我确实向我的虚拟主机支持寻求帮助,但我没有得到任何可用的答案。另外,由于他们是经销商,我不太确定他们能提供多少帮助。

有没有办法克服这个问题?欢迎提出任何建议。

提前致谢

--------------------------------更新------------ ----------------------------------------

#!/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")

这就是我的配置。我必须承认有一点错误(解释器路径),但是“设置”文件路径是好的。

在将解释器路径更正为正确的路径后,首先我遇到了 StringError(其中一个 djangos 文件中的一些三引号文档字符串未关闭 - 嗯,几乎没有),比在下一次运行 < strong>MemoryError,然后又是 MemoryError 等等。一段时间(一个小时)后,我尝试再次执行脚本(没有做进一步的更改)并不断以段错误(核心已转储)结束。

有什么建议吗?

最佳答案

从命令行运行它时,您需要明确指定 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 文件是否仍然具有适用于您的 .fcgi 脚本的正确的 RewriteRule

关于共享主机中的python MemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7804305/

相关文章:

php - 哪个 PHP 5 版本最常用?

asp.net - Entity Framework 与数据访问层

python - 打印列表中除 Python 中的一个之外的所有字符串元素

python - 为什么 Django 显示 KeyError?

python - 如何在Django中获取导致IntegrityError的记录

python - 模型中的 Django 循环导入

php - 共享主机安全吗?

python - 捕获花括号内的内容

python - 如何查找特定标签下的保留实例总数?

python - Django url include 模块显示由空格分隔的 url