偶尔ctypes的错误从mod_wsgi的Django应用程序导入numpy的 [英] Occasional ctypes error importing numpy from mod_wsgi django app

查看:381
本文介绍了偶尔ctypes的错误从mod_wsgi的Django应用程序导入numpy的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的设置:


  • 的Django(1.2)上mod_wsgi的应用程序,进口ctypes的

  • 的Python 2.6.5

  • 的Apache 2.2.3

  • 的SELinux禁用

  • 的RedHat EL 5 64

  • 某些文件系统被安装在NFS

有时,当我重新启动Apache,我得到,当它试图导入ctypes的进口错误。每个进入的请求失败,出现500错误。如果我重新启动Apache通常一切都只是开始工作了。

Occasionally, when I restart apache I get an import error when it's trying to import ctypes. Every incoming request fails with a 500 error. If I restart apache usually everything just starts working again.

下面是错误的堆栈跟踪:

Here's the stack trace of the error:

Traceback (most recent call last):

 File "/home/appfirst/django/django/core/handlers/base.py", line 80, in get_response
   response = middleware_method(request)

     -------------- A BUNCH OF DJANGO MIDDLEWARE STUFF HERE -------------

 File "/home/appfirst/django/django/utils/importlib.py", line 35, in import_module
   __import__(name)

 File "/home/appfirst/backend/backend/streamer/views.py", line 6, in <module>
   import appfirst.main.models as FEmodels

 File "/home/appfirst/frontend/appfirst/main/models.py", line 27, in <module>
   import numpy, math, mpmath

 File "/usr/lib64/python2.6/site-packages/numpy/__init__.py", line 43, in <module>
   import ctypeslib

 File "/usr/lib64/python2.6/site-packages/numpy/ctypeslib.py", line 9, in <module>
   import ctypes

 File "/usr/lib64/python2.6/ctypes/__init__.py", line 546, in <module>
   CFUNCTYPE(c_int)(lambda: None)

MemoryError

我想这可能与此有关的错误,但我的SELinux关闭我本以为这意味着这种情况下,可能永远不会发生:

I thought it might be related to this bug, but I have SELinux turned off which I thought would mean this case could never occur:

  • http://bugs.python.org/issue5504

如何始终如一地重现和/或解决它有什么建议?这实在是两腿发僵我!

Any suggestions on how to reproduce it consistently and/or fix it? This is really stumping me!

推荐答案

我碰到的这个bug了。在我来说,当我从64位Linux系统上的Apache下运行PHP脚本Exec的Python脚本发生。 [Python的code是运行的是前端到pypy沙箱。] code的同一位工作正常在32位系统上,甚至当直接在命令执行的PHP脚本工作正常线。我的修复的,只不过是注释掉该行CFUNCTYPE(c_int的)(拉姆达:无)中的ctypes / 的init 的.py。这是文件的最后一行是由以下评论pceded $ P $,可见程序员不明白这是怎么回事,要么!

I've run into this bug too. In my case it occurs when I exec a Python script from within a PHP script running under Apache on a 64-bit Linux system. [The Python code being run is the front-end to a pypy sandbox.] The same bit of code works fine on a 32-bit system and even works fine when the PHP script is executed directly from the command line. My "fix" has been simply to comment out that line "CFUNCTYPE(c_int)(lambda: None)" in ctypes/init.py. It's the last line of the file and is preceded by the following comment, showing that the programmer doesn't understand what's going on, either!

# 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)

显然,在CPython的地方是一个更深层次的问题,但修复为我工作。

Clearly there's a deeper problem somewhere in cpython, but the fix works for me.

这篇关于偶尔ctypes的错误从mod_wsgi的Django应用程序导入numpy的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆