Pickle can't store an object in django locmem cache during tests?

前端 未结 4 486
天命终不由人
天命终不由人 2021-01-25 02:27

Something that\'s puzzling me a bit...

>>> from django.core.cache import get_cache
>>>
>>> cache = get_cache(\'django.core.cache.backe         


        
4条回答
  •  耶瑟儿~
    2021-01-25 02:52

    sample code

    import pickle  # or from django.utils.six.moves import cPickle as pickle
    lass TestObj(object):
         pass
    testobj = TestObj()   
    pickled = pickle.dumps(testobj, pickle.HIGHEST_PROTOCOL)
    pickled
    '\x80\x02c__main__\nTestObj\nq\x00)\x81q\x01}q\x02b.'
    

    i can't understand a behavior, when i open a console session with "python manage.py shell" and execute: _pickle.PicklingError: Can't pickle : attribute lookup builtins.TestObj failed

    but when open a single python console and execute the same code, works fine! Is there a reason?

    I observed too, if i open a single console, and import from django.utils.six.moves import cPickle as pickle works fine too. The problem just occours when the code is executed in django context. :(

提交回复
热议问题