【问题标题】:python MemoryError in shared hosting共享主机中的python MemoryError
【发布时间】:2011-12-09 21:32:43
【问题描述】:

我试图在不是 django 特定的共享网络主机上部署 django。 Host 提供了旧版本的 python 安装,但由于我有 ssh 访问能力,我设法通过在我的主文件夹中本地安装它们来扩展 python 安装与我需要的模块(包括 django)。 好的,所以我创建了 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 吗? 更糟糕的是,一个月前,同一个提供商给了我一个测试帐户,并且 a 不仅能够运行 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 文件中的一些三引号文档字符串没有关闭 - 嗯,几乎没有),而不是下一次运行 MemoryError,再次MemoryError等等。过了一会儿(一个小时),我再次尝试执行脚本(没有进行进一步的更改),并不断以 Segmentation fault (core dumped) 告终。

有什么建议吗?

【问题讨论】:

  • 为什么你确定它是关于内存有限的?前四行提到了缺少的参数。也就是说,stackoverflow.com/questions/800584/…stackoverflow.com/questions/2526172/… 的答案对你有什么帮助吗?
  • 谢谢回复。四个缺少的参数导致脚本是从 shell 触发的,而不是作为常规浏览器请求。尽管如此,它必须给我正确的响应,在这种情况下应该是 django 成功页面。

标签: python django shared-hosting shared-memory


【解决方案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 脚本。

【讨论】:

  • 我已经更新了我的问题。你能再帮我一些吗?谢谢。
  • @NikolaTrbojevic:我对此有点不确定。我从来没有在这样的环境中部署过 Django,但是 Django 的书有一个chapter dedicated to deployment。查找“处理分段错误”和“使用 Apache 在共享主机提供商上运行 Django”这两个段落。我不知道你是否已经读过,但也许你会找到一些可能的答案。
猜你喜欢
  • 2013-01-06
  • 2018-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
  • 1970-01-01
  • 2011-04-20
相关资源
最近更新 更多