Adding a shared object to a manager.Namespace

柔情痞子 提交于 2019-12-13 03:49:39

问题


This seems to be a python 3.6 bug

When assigning a manager.Queue to a manager.Namespace attribute one gets an TypeError. To reproduce it is simple:

>>> from multiprocessing import Manager
>>> manager = Manager()
>>> np = manager.Namespace()
>>> np.shared_queue = manager.Queue()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\users\leonardo.schettini\appdata\local\programs\python\python36-32\Lib\multiprocessing\managers.py", line 1065, in __setattr__
    return callmethod('__setattr__', (key, value))
File "c:\users\leonardo.schettini\appdata\local\programs\python\python36-32\Lib\multiprocessing\managers.py", line 772, in _callmethod
    raise convert_to_error(kind, result)
multiprocessing.managers.RemoteError:
---------------------------------------------------------------------------
Traceback (most recent call last):
File "c:\users\leonardo.schettini\appdata\local\programs\python\python36-32\Lib\multiprocessing\managers.py", line 228, in serve_client
    request = recv()
File "c:\users\leonardo.schettini\appdata\local\programs\python\python36-32\Lib\multiprocessing\connection.py", line 251, in recv
    return _ForkingPickler.loads(buf.getbuffer())
File "c:\users\leonardo.schettini\appdata\local\programs\python\python36-32\Lib\multiprocessing\managers.py", line 881, in RebuildProxy
    return func(token, serializer, incref=incref, **kwds)
TypeError: AutoProxy() got an unexpected keyword argument 'manager_owned'
---------------------------------------------------------------------------

Here, I found that manager.Queue is just

an address (proxy) pointing to shared queue managed by the multiprocessing.Manager() object

If one tries to assign a multiprocessing.Queue instead a RuntimeError is raised. This makes sense if you consider that the multiprocessing.Queue can't be pickled (information on provided link)

来源:https://stackoverflow.com/questions/50508310/adding-a-shared-object-to-a-manager-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!