python代码内存溢出报错

环境是

4核+8G的7.3CentOS系统(强调,系统是64位的)

 

[2018-07-03 15:37:58,098][MainThread:140513684158528][task_id:web.signals.notice_signal][notice_signal.py:1011][ERROR]['>=' not supported between instances of 'str' and 'int']
[2018-07-03 15:54:26,825][b'uWSGIWorker5Core0':140397910317120][task_id:django.request][exception.py:135][ERROR][Internal Server Error: /api/v1/XXX/]
Traceback (most recent call last):
  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/handlers/base.py", line 217, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/core/handlers/base.py", line 215, in _get_response
    response = response.render()
  File "/usr/local/python3.6.2/lib/python3.6/site-packages/django/template/response.py", line 107, in render
    self.content = self.rendered_content
  File "/usr/local/python3.6.2/lib/python3.6/site-packages/rest_framework/response.py", line 72, in rendered_content
    ret = renderer.render(self.data, accepted_media_type, context)
  File "/usr/local/python3.6.2/lib/python3.6/site-packages/rest_framework/renderers.py", line 105, in render
    separators=separators
  File "/usr/local/python3.6.2/lib/python3.6/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/local/python3.6.2/lib/python3.6/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/python3.6.2/lib/python3.6/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
MemoryError

 

这种内存溢出错误。一旦报错就是一堆堆的报错,完全找不到头绪,

找了好久发现这种错误主要是两点原因。

1.Python解释器是32位的(或者只支持32位),当内存使用率到了2GB以上之后,就会内存溢出,好比   java设置了2G

2.代码级别的循环调用,百度一下有很多这个原因的。

 

解决方案重新编译安装python解释器

 

./configure --prefix=/usr/local/python3.6.2 --with-ssl --with-universal-archs=all

make

make install

  

其中 --with-universal-archs=all  

select architectures for universal build ("32-bit","64-bit", "3-way", "intel", "intel-32", or "all")

选择 architectures进行构建,然后我选择了all进行构建。其中 intel是英特尔芯片的意思。

posted @ 2018-07-03 17:08  汉克书  阅读(4158)  评论(0编辑  收藏  举报