【问题标题】:Django memcached library for python3python3的Django memcached库
【发布时间】:2015-12-13 12:56:37
【问题描述】:

我正在尝试将 memcached 用于我的 Django 1.8.5(python3 下)网站。

目前我已经尝试过 pylibmc 和 python-memcached。

pylibmc 给我这个错误

libmemcached/get.cc:87 Assertion "ptr->query_id == query_id +1" failed for function "memcached_get_by_key" likely for "Programmer error, the query_id was not incremented."
Number of stack frames obtained: 24
  /usr/lib/x86_64-linux-gnu/libmemcached.so.10 : memcached_get_by_key()+0x283
  /usr/lib/x86_64-linux-gnu/libmemcached.so.10 : memcached_get()+0x1f
  /home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/_pylibmc.cpython-34m.so : ()+0x61fd
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x3f6a
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalCodeEx()+0x15b
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x4490
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalCodeEx()+0x15b
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x4490
 /home/francesco/virtualenvs/TeamCompSite/bin/python() [0x56a7ec]
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyObject_Call()+0x3a
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x1e2f
 /home/francesco/virtualenvs/TeamCompSite/bin/python() [0x56a7ec]
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyObject_Call()+0x3a
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x1e2f
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x403d
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_EvalFrameEx()+0x403d
 /home/francesco/virtualenvs/TeamCompSite/bin/python() [0x56a7ec]
 /home/francesco/virtualenvs/TeamCompSite/bin/python() [0x4e21bd]
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyObject_Call()+0x3a
  /home/francesco/virtualenvs/TeamCompSite/bin/python : PyEval_CallObjectWithKeywords()+0x36
 /home/francesco/virtualenvs/TeamCompSite/bin/python() [0x5be452]
  /lib/x86_64-linux-gnu/libpthread.so.0 : ()+0x8182
  /lib/x86_64-linux-gnu/libc.so.6 : clone()+0x6d

看起来真的很稀有,在google上我只找到pylibmc: 'Assertion "ptr->query_id == query_id +1" failed for function "memcached_get_by_key"'

不幸的是,我无法更改 django 处理 memcached 库的方式..

然后我尝试了 python-memcached

这次我得到了

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f00537e9f28>
Traceback (most recent call last):
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
    autoreload.raise_last_exception()
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/autoreload.py", line 252, in raise_last_exception
    six.reraise(*_exception)
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/media/francesco/A6528DA1528D76B9/Programmazione/Python/Spark/team_comp_site/teamcomp/apps.py", line 19, in ready
    client.get_stats()
  File "/home/francesco/virtualenvs/TeamCompSite/lib/python3.4/site-packages/memcache.py", line 338, in get_stats
    stats = line.split(' ', 2)
TypeError: 'str' does not support the buffer interface

看起来 python-memcached 只支持 python2(我不事先检查不好)

让我们试试 python3-memcached

网站加载!!!

只是为了给我看熟悉的错误页面

Exception Value:    local variable 'val' referenced before assignment

Exception Location:     /home/xxxxx/virtualenvs/xxxx/lib/python3.4/site-packages/memcache.py in _recv_value, line 1026
Python Executable:  /home/xxxxx/virtualenvs/xxxxx/bin/python
Python Version:     3.4.3

那么,python3 (.4) memcached 客户端有哪些选项?

【问题讨论】:

    标签: django python-3.x memcached


    【解决方案1】:

    使用 python3-memcached 只是触发了一个更干净的字符串和字节缓冲区管理。

    在 python2 中,unicode 字符串是字节数组,字符串是 ascii 或 \uXXXX 字符链。 ascii 字符串到字节串之间的转换是静默的,但从字节串到字符串是显式的。

    在 python3 中:unicode 类型不再存在。你只有str 和裸bytearray。因此,一切都必须是明确的,因此一切都更加可预测。 python-memcached 库经过重新开发以适应这种新的、更简单的方法来处理 py3 中的字符串。

    【讨论】:

      猜你喜欢
      • 2013-05-23
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 2015-09-17
      相关资源
      最近更新 更多