0

I assign an instance object (q) of the multiprocessing.Manaager().Queue() to one item of the instance object (d) of the multiprocessing.Manager().dict(), but I cannot reuse the q in the dict.

The version of the Python is 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)    

OUTPUT

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>}
Yogev Neumann
  • 2,099
  • 2
  • 13
  • 24
  • Hi - Welcome to Stack Overflow. Code only questions aren't very useful. Can you please tell us what you are trying to do? – dwjohnston Nov 28 '18 at 01:02
  • @dwjohnston I want to assign the instance object of multiprocessing.Manager().Queue() (q) to a dictionary (d), then reuse the instance object of multiprocessing.Manager().Queue() with dict (such as d['10.10.10.102_1024'] ) – Congming SHI Nov 28 '18 at 01:12
  • Can you please format your question correctly? - There is the `<>` button that will indent it so the code blocks show up properly. – dwjohnston Nov 28 '18 at 01:38

0 Answers0