python – 通过multiprocessing.queue发送字典会以某种方式改变它吗?

我有一个设置,我通过multiprocessing.queue发送字典,并用它做一些事情.当我没有更改字典中的任何内容时,我得到了一个奇怪的“字典大小在迭代时更改了”错误.这是追溯,虽然它不是非常有用:

Traceback (most recent call last):
  File "/usr/lib/python2.6/multiprocessing/queues.py", line 242, in _feed
    send(obj)
RuntimeError: dictionary changed size during iteration

所以我尝试将字典更改为immutable dictionary以查看它被改变的位置.这是我得到的追溯:

Traceback (most recent call last):
  File "/home/jason/src/interface_dev/jiva_interface/jiva_interface/delta.py", line 54, in main
    msg = self.recv()
  File "/home/jason/src/interface_dev/jiva_interface/jiva_interface/process/__init__.py", line 65, in recv
    return self.inqueue.get(timeout=timeout)
  File "/usr/lib/python2.6/multiprocessing/queues.py", line 91, in get
    res = self._recv()
  File "build/bdist.linux-i686/egg/pysistence/persistent_dict.py", line 22, in not_implemented_method
    raise NotImplementedError, 'Cannot set values in a PDict'
NotImplementedError: Cannot set values in a PDict

这有点奇怪,因为据我所知,除了从队列中获取它之外我什么也做不了.有人能否对这里发生的事情有所了解?

最佳答案 最近修复了一个错误,其中垃圾收集可能会更改包含弱引用的字典的大小,并且可能会触发“字典在迭代期间更改的大小”错误.我不知道这是你的问题,但多处理包确实使用弱引用.

http://bugs.python.org/issue7105

点赞