2016-06-09 42 views
0

我在我的django項目中遇到了這個問題,我相信它與緩存有關。它每六個月出現一次,通過重新啓動應用程序「固定」,僅在幾個月後回來。突然之間,所有的意見將失敗,這種例外。弱小的對象已經消失了? - python/django

TypeError: weak object has gone away 

而且它並不總是相同的對象,每個視圖失敗,並試圖訪問一個不同的對象。在這種情況下,它訪問用戶(使用request.user.is_authenticated()),但其他頁面與其他對象一起訪問。

我在想這些緩存肯定有問題。也許它在django甚至是一個問題。我不知道。它只是運行良好,直到它沒有,似乎沒有人在互聯網上談論這個例外。

下面是一個簡單回溯:

Traceback (most recent call last): 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/core/handlers/base.py", line 88, in get_response 
    response = middleware_method(request) 

    File "/home/rsaenz/webapps/club/club/cms/socios/views.py", line 143, in process_request 
    if not request.user.is_authenticated(): 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/utils/functional.py", line 213, in inner 
    self._setup() 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/utils/functional.py", line 298, in _setup 
    self._wrapped = self._setupfunc() 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 18, in <lambda> 
    request.user = SimpleLazyObject(lambda: get_user(request)) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 10, in get_user 
    request._cached_user = auth.get_user(request) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 140, in get_user 
    user_id = request.session[SESSION_KEY] 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py", line 47, in __getitem__ 
    return self._session[key] 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py", line 173, in _get_session 
    self._session_cache = self.load() 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py", line 20, in load 
    expire_date__gt=timezone.now() 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get 
    return self.get_queryset().get(*args, **kwargs) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/query.py", line 301, in get 
    clone = self.filter(*args, **kwargs) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/query.py", line 593, in filter 
    return self._filter_or_exclude(False, *args, **kwargs) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/query.py", line 611, in _filter_or_exclude 
    clone.query.add_q(Q(*args, **kwargs)) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1204, in add_q 
    clause = self._add_q(where_part, used_aliases) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1240, in _add_q 
    current_negated=current_negated) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1131, in build_filter 
    clause.add(constraint, AND) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/utils/tree.py", line 104, in add 
    data = self._prepare_data(data) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/db/models/sql/where.py", line 61, in _prepare_data 
    if is_iterator(value): 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/site-packages/django/utils/itercompat.py", line 30, in is_iterator 
    return isinstance(x, collections.Iterator) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/abc.py", line 144, in __instancecheck__ 
    return cls.__subclasscheck__(subtype) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/abc.py", line 184, in __subclasscheck__ 
    cls._abc_negative_cache.add(subclass) 

    File "/home/rsaenz/virtualenvs/club/lib/python2.7/_weakrefset.py", line 86, in add 
    self.data.add(ref(item, self._remove)) 

TypeError: weak object has gone away 

的感謝!

回答

0

基於回溯,這看起來更像是一個Python weakrefset問題,collections.Iterator依賴於abc(抽象基類)模塊。

+0

那麼你認爲解決方案是什麼?如果這是一個python問題,那麼我需要完全避免這些緩存? –

+0

很難說。你在這裏使用gunicorn? –