Я назначаю объект экземпляра (q) функции multiprocessing.Manaager (). Queue () одному элементу объекта экземпляра (d) функции multiprocessing.Manager (). Dict (), но я не могу повторно использовать qв поле.
Версия Python - 2.7.15.
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
from multiprocessing import Process, Manager
def f(d):
xx = d['10.10.10.102_1024']
xx.put(11)
d['ddd'] = 8888888888
def test1(d,manager):
q = manager.Queue()
try:
d['10.10.10.102_1024'] = q
except Exception as error:
print error
if __name__ == '__main__':
manager = Manager()
d = manager.dict()
test1(d,manager)
p = Process(target=f, args=(d,))
p.start()
p.join()
print(d)
ВЫХОД
Process Process-2:
Traceback (most recent call last):
File "/Users/shicongming/anaconda2/lib/python2.7/multiprocessing/process.py", line 267, in _bootstrap
self.run()
File "/Users/shicongming/anaconda2/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "test_dict.py", line 8, in f
xx = d['10.10.10.102_1024']
File "<string>", line 2, in __getitem__
File "/Users/shicongming/anaconda2/lib/python2.7/multiprocessing/managers.py", line 774, in _callmethod
raise convert_to_error(kind, result)
RemoteError:
---------------------------------------------------------------------------
Unserializable message: Traceback (most recent call last):
File "/Users/shicongming/anaconda2/lib/python2.7/multiprocessing/managers.py", line 288, in serve_client
send(msg)
TypeError: can't pickle thread.lock objects
---------------------------------------------------------------------------
{'10.10.10.102_1024': <Queue.Queue instance at 0x10f5b01b8>}