我最近在Python2.7中遇到了一个奇怪的行为。你知道吗
>>> import multiprocessing as mp
>>> lst = mp.Manager().list()
>>> lst.append([1,2])
>>> lst.append([3,4])
>>> print(lst)
[[1, 2], [3, 4]]
>>> lst[0][1] = 123
>>> print(lst)
[[1, 2], [3, 4]]
嗯?为什么多重处理列表的第一个元素没有更改?它适用于普通列表!你知道吗
让我们换一种方式试试。你知道吗
>>> lst[0] = [1,123]
>>> print(lst)
[[1, 123], [3, 4]]
好吧,至少我有个解决办法。但是为什么第一个代码片段中的assignmentlst[0][1] = 123
不起作用呢?你知道吗
我试图解决你的问题,以下是我遇到的情况:
多亏了this question。你知道吗
因此,似乎不是数据结构本身的问题,而是管理它的问题。因此,我根据the docs创建了一个进程:
给我以下结果:
当我尝试使用
args[0][0][1] = 123
进行分配时,没有发生任何更改,因此需要一种解决方法或其他方法。你知道吗相关问题 更多 >
编程相关推荐