PIL库中fcgi进程中的Python ctypes MemoryError
我正在尝试在共享主机(Bluehost)上运行Django。我正在使用需要PIL的功能。PIL从一个交互式shell导入和工作,但在我的fcgi过程中,它在从PIL导入映像中崩溃,内存错误。任何关于它在fcgi中失败原因的帮助都将不胜感激PIL库中fcgi进程中的Python ctypes MemoryError,python,django,python-imaging-library,fastcgi,Python,Django,Python Imaging Library,Fastcgi,我正在尝试在共享主机(Bluehost)上运行Django。我正在使用需要PIL的功能。PIL从一个交互式shell导入和工作,但在我的fcgi过程中,它在从PIL导入映像中崩溃,内存错误。任何关于它在fcgi中失败原因的帮助都将不胜感激 __Environment Info__: Python2.7 Local installs of libjpg, zlib, freetype, and lcms Virtualenv: Django 1.3, PIL, flup, etc.
__Environment Info__:
Python2.7
Local installs of libjpg, zlib, freetype, and lcms
Virtualenv:
Django 1.3, PIL, flup, etc.
__Stack Trace__:
File ".../feincms_thumbnail.py", line 3, in <module>
from PIL import Image
File ".../PIL/Image.py", line 45, in <module>
\__import__("FixTk")
File ".../python2.7/lib-tk/FixTk.py", line 15, in <module>
import ctypes
File ".../python2.7/ctypes/__init__.py", line 549, in <module>
CFUNCTYPE(c_int)(lambda: None)
__.fcgi__:
<!-- language: python -->
# setup paths
# set DJANGO_SETTINGS_MODULE in os.environ
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
环境信息:
蟒蛇2.7
libjpg、zlib、freetype和lcms的本地安装
虚拟电视:
Django 1.3、PIL、flup等。
__堆栈跟踪\uuux:
文件“../feincms\u缩略图.py”,第3行,在
从PIL导入图像
文件“../PIL/Image.py”,第45行,在
\__导入(“FixTk”)
文件“../python2.7/lib-tk/FixTk.py”,第15行,在
导入ctypes
文件“../python2.7/ctypes/_init__uu.py”,第549行,在
CFUNCTYPE(c_int)(lambda:None)
__.fcgi_uuu:
#设置路径
#在os.environ中设置DJANGO_设置_模块
从django.core.servers.fastcgi导入runfastcgi
runfastcgi(method=“threaded”,daemonize=“false”)
我暂时修复了注释此文件最后一行时出现的错误$HOME/lib/python2.7/ctypes/\uuuu init\uuuuuuuuuuuuuy.py
类似于\CFUNCTYPE(c\u int)(lambda:None)
这对我来说是可行的,但我不知道到底是什么问题
更新
在Python2.7.3中,行号是:279,而不是我上面所说的最后一行
更新2
由于行在次要版本之间可能有所不同,因此您应该查找类似以下内容的代码块:
# XXX for whatever reasons, creating the first instance of a callback
# function is needed for the unittests on Win64 to succeed. This MAY
# be a compiler bug, since the problem occurs only when _ctypes is
# compiled with the MS SDK compiler. Or an uninitialized variable?
CFUNCTYPE(c_int)(lambda: None)
仅对eos87的答案进行一点扩展,这也解决了我的问题,从这一行之前的评论来看,这听起来像是作为windows bug的解决方案添加的,但该解决方案显然是自己造成麻烦的。以下是
\uuuu init\uuuuuuy.py
末尾的位:
# XXX for whatever reasons, creating the first instance of a callback
# function is needed for the unittests on Win64 to succeed. This MAY
# be a compiler bug, since the problem occurs only when _ctypes is
# compiled with the MS SDK compiler. Or an uninitialized variable?
CFUNCTYPE(c_int)(lambda: None)
看起来移除是安全的
FWIW,当我使用从安装的Python2.6(与Python2.4并行)时,这个问题在Centos 5.7 x64上出现。在这里可以找到该文件:/usr/lib64/python2.6/ctypes/\uuu init\uuuu.py
还请注意,出现的异常是一个MemoryError,根据
strace
,它是在调用munmap
后立即(尽管可能是巧合)由分段错误导致的;并且它仅在作为FastCGI运行时显示。尝试运行以下命令:
setsebool -P httpd_tmp_exec on
在CentOS上为我解决问题。摘自本帖:
作为一种替代方法,我修改了Django,使用ImageMagick代替PIL()。在接下来的一两天里,我会尝试一下你的方法,看看它对我是否有效。+1-哈克,但有效。是否已报告此问题?非常讨厌的错误,希望有人正在处理。有其他解决方案吗?hack可以工作,但是需要看看是否有更好的方法来解决这个问题。我解决这个问题的方式有点不同——请看,只有在您的设置中启用了SELinux时,这才有效。在其他情况下,我们必须依赖于其他答案,我想。。。。