相关疑难解决方法(0)

PicklingError:不能pickle <class'minit.Decimal'>:它与decimal.Decimal不是同一个对象

这是我今天在http://filmaster.com"> filmaster.com上遇到的错误:

PicklingError:不能pickle:它与decimal.Decimal不是同一个对象

这究竟意味着什么?它似乎没有多大意义......它似乎与django缓存有关.你可以在这里看到整个追溯:

Traceback(最近一次调用最后一次):

文件"/home/filmaster/django-trunk/django/core/handlers/base.py",第92行,在get_response response = callback(request,*callback_args,**callback_kwargs)

在show_film
workflow.set_data_for_authenticated_user()中输入文件"/home/filmaster/film20/film20/core/film_views.py",第193行

文件"/home/filmaster/film20/film20/core/film_views.py",第518行,在set_data_for_authenticated_user
object_id = self.the_film.parent.id)

在get_others_ratings
set_cache 中输入文件"/home/filmaster/film20/film20/core/film_helper.py",第179行(CACHE_OTHERS_RATINGS,str(object_id)+"_"+ str(user_id),userratings)

文件"/home/filmaster/film20/film20/utils/cache_helper.py",第80行,在set_cache中返回cache.set(CACHE_MIDDLEWARE_KEY_PREFIX + full_path,result,get_time(cache_string))

文件"/home/filmaster/django-trunk/django/core/cache/backends/memcached.py",第37行,设置为
self._cache.set(smart_str(key),value,timeout或self.default_timeout)

文件"/usr/lib/python2.5/site-packages/cmemcache.py",第128行,在set val中,flags = self._convert(val)

文件"/usr/lib/python2.5/site-packages/cmemcache.py",第112行,在_convert val = pickle.dumps(val,2)

PicklingError:不能pickle:它与decimal.Decimal不是同一个对象

Filmaster的源代码可以从这里下载:bitbucket.org/filmaster/filmaster-test

任何帮助将不胜感激.

python django pickle

32
推荐指数
6
解决办法
3万
查看次数

对对象进行酸洗 lru_cached 函数

作为并行化某些现有代码(使用多处理)的一部分,我遇到了需要对类似于下面的类的内容进行腌制的情况。

从...开始:

import pickle
from functools import lru_cache

class Test:
    def __init__(self):
        self.func = lru_cache(maxsize=None)(self._inner_func)

    def _inner_func(self, x):
        # In reality this will be slow-running
        return x
Run Code Online (Sandbox Code Playgroud)

呼叫

t = Test()
pickle.dumps(t)
Run Code Online (Sandbox Code Playgroud)

回报

_pickle.PicklingError: Can't pickle <functools._lru_cache_wrapper object at 0x00000190454A7AC8>: it's not the same object as __main__.Test._inner_func
Run Code Online (Sandbox Code Playgroud)

我不太明白。顺便说一句,我还尝试了一种变体,其中 _inner_func 的名称也为 func,但这并没有改变任何事情。

python serialization pickle lru

5
推荐指数
1
解决办法
2492
查看次数

为什么并发.futures.ProcessPoolExecutor和multiprocessing.pool.Pool在Python中使用super失败?

为什么以下使用该concurrent.futures模块的Python代码会永远挂起?

import concurrent.futures


class A:

    def f(self):
        print("called")


class B(A):

    def f(self):
        executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)
        executor.submit(super().f)


if __name__ == "__main__":
    B().f()
Run Code Online (Sandbox Code Playgroud)

这个调用产生了一个无形的例外[Errno 24] Too many open files(见它,更换线路executor.submit(super().f)用print(executor.submit(super().f).exception()))。

但是,按预期将打印替换ProcessPoolExecutor为ThreadPoolExecutor“被调用”。

为什么以下使用该multiprocessing.pool模块的Python代码引发异常AssertionError: daemonic processes are not allowed to have children?

import multiprocessing.pool


class A:

    def f(self):
        print("called")


class B(A):

    def f(self):
        pool = multiprocessing.pool.Pool(2)
        pool.apply(super().f)


if __name__ == "__main__":
    B().f()
Run Code Online (Sandbox Code Playgroud)

但是,按预期将打印替换Pool为ThreadPool“被调用”。

环境:CPython 3.7,MacOS …

python pickle python-multiprocessing process-pool

5
推荐指数
1
解决办法
544
查看次数