[pyar] Es esto un bug en Python? multiprocessing.Manager
Juanjo Conti
jjconti en gmail.com
Mie Sep 1 10:25:27 ART 2010
Encontré un comportamiento que me sorprendió en multiprocessing.Manager. No
se puede iterar sobre el objeto proxy que representa un dict (objeto
compartido entre procesos).
>>> from multiprocessing import Manager
>>> m = Manager()
>>> d = m.dict()
>>> d
<DictProxy object, typeid 'dict' at 0x98a240c>
>>> for x in d:
... print x
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2, in __getitem__
File "/usr/lib/python2.6/multiprocessing/managers.py", line 740, in
_callmethod
raise convert_to_error(kind, result)
KeyError: 0
>>> d['a'] = 1
>>> for x in d:
... print x
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2, in __getitem__
File "/usr/lib/python2.6/multiprocessing/managers.py", line 740, in
_callmethod
raise convert_to_error(kind, result)
KeyError: 0
>>> d[1] = 1
>>> for x in d:
... print x
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2, in __getitem__
File "/usr/lib/python2.6/multiprocessing/managers.py", line 740, in
_callmethod
raise convert_to_error(kind, result)
KeyError: 0
>>> for x in d.keys():
... print x
...
a
1
>>> d = m.dict()
>>> for x in d.keys():
... print x
Les parece un error o una feature?
Por si se preguntan, con listas si anda:
>>> l = m.list()
>>> for x in l:
... print x
...
--
Juanjo Conti
blog: http://www.juanjoconti.com.ar
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20100901/97da065a/attachment.html>
More information about the pyar
mailing list