开发者

django-keyedcache: NameError: global name 'tid' is not defined

Can't put my finger on this error. In other parts of the application it works fine, but not in this one, the only thing that is different that this code runs in threaded server while the other runs in preforked. On the other hand, on another production server it works fine in threaded server too.

File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
  response = callback(request, *callback_args, **callback_kwargs)

File "/usr/lib/python2.6/site-packages/django/views/decorators/http.py", line 45, in inner
  return func(request, *args, **kwargs)

File "/home/asia/myfilm/torrent/tracker.py", line 138, in announce
  announce_interval = cache_get(ck)

File "/home/asia/myfilm/keyedcache/__init__.py", line 207, in cache_get
  cache_set_request(key, obj, uid=tid)

File "/home/asia/myfilm/keyedcache/__init__.py", line 329, in cache_set_request
  REQUEST_CACHE[uid][key] = val

NameError: global name 'tid' is not defined

The code part causing this exception (around line 207):

    obj = None
    tid = -1
    if REQUEST_CACHE['enabled']:
        tid = cache_get_request_uid()
        if tid > -1:
            try:
                obj = REQUEST_CACHE[tid][key]
                log.debug('Got from request cache: %s', key)开发者_如何学编程
            except KeyError:
                pass

    if obj == None:
        obj = cache.get(key)

    if obj and isinstance(obj, CacheWrapper):
        CACHE_HITS += 1
        CACHED_KEYS[key] = True
        log.debug('got cached [%i/%i]: %s', CACHE_CALLS, CACHE_HITS, key)
        if obj.inprocess:
            raise MethodNotFinishedError(obj.val)

        cache_set_request(key, obj, uid=tid)

And below (around line 329):

def cache_set_request(key, val, uid=None):
    if uid == None:
        uid = cache_get_request_uid()

    if uid>-1:
        global REQUEST_CACHE
        if not uid in REQUEST_CACHE:
            REQUEST_CACHE[uid] = {key:val}
        else:
            REQUEST_CACHE[uid][key] = val

As far as I can see, tid IS defined there, I can't see what's causing the problem.


It appears my setup was invalid. Old .pyc files etc. In fact it was a little more complex than that but nevertheless, it works now. Sorry for the possible confusion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜