Когда я применяю multiprocessing.pool.map
к list
объекту, объект list
не будет затронут:
from multiprocessing import Pool
def identity(x):
return x
num_list = list(range(0, 10))
print("before multiprocessing:")
with Pool(10) as p:
print(p.map(identity, num_list))
print("after multiprocessing:")
print(list(num_list))
печатает
before multiprocessing:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
after multiprocessing:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Но когда я применяю multiprocessing.pool.map
на map
объекте, кажется, он был стерт:
from multiprocessing import Pool
def identity(x):
return x
num_list = list(range(0, 10))
num_list = map(identity, num_list)
print("before multiprocessing:")
with Pool(10) as p:
print(p.map(identity, num_list))
print("after multiprocessing:")
print(list(num_list))
печатает
before multiprocessing:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
after multiprocessing:
[]
Единственное отличие - num_list = map(identity, num_list)
.
Имеет num_list
(объект карты) был удален multiprocessing.pool.map
?
Я не уверен в этом, но я не мог найти другое объяснение.