当我运行以下代码时:
import multiprocessing
sum1 = 0
def list_append_1(out_list):
global sum1
for i in out_list:
sum1 += i
return sum1
lista_1 = [i for i in xrange(500)]
process_1 = multiprocessing.Process(target=list_append_1, args=lista_1)
jobs = []
jobs.append(process_1)
for j in jobs:
j.start()
我明白了:
TypeError: list_append_1() takes exactly 1 argument (500 given)
虽然我只将一个参数传递给list_append_1()
函数。有什么问题?
答案 0 :(得分:1)
参数应该通过这种方式传递:
process_1 = multiprocessing.Process(target=list_append_1, args=(lista_1,))