別の関数で辞書clean_txt内のリストを操作しようとしていますが、機能していないため、空リストが辞書内にあります。変数を別の関数内の関数にローカルで変更できません
リストと辞書の両方が可変オブジェクトなので、ここで何が問題なのですか?
def process_questions(i, question_list, questions, question_list_name):
''' Transform questions and display progress '''
print('processing {}: process {}'.format(question_list_name, i))
for question in questions:
question_list.append(text_to_wordlist(str(question)))
@timeit
def multi(n_cores, tq, qln):
procs = []
clean_txt = {}
for i in range(n_cores):
clean_txt[i] = []
for index in range(n_cores):
tq_indexed = tq[index*len(tq)//n_cores:(index+1)*len(tq)//n_cores]
proc = Process(target=process_questions, args=(index, clean_txt[index], tq_indexed, qln,))
procs.append(proc)
proc.start()
for proc in procs:
proc.join()
print('{} records processed from {}'.format(sum([len(x) for x in clean_txt.values()]), qln))
print('-'*100)
親プロセスに属していると言うのは間違いです:) – Maresh
@Maresh彼はメインプロセスで 'clean_txt [i] = []'を実行していますので、そのリストはメインプロセスの権利に属しますか? –
それぞれのプロセスは、親プロセスのものからコピーされた独自のメモリ空間を持ちます。マルチプロセッシングで遊ぶときは、それを理解することが重要です。最後にあなたは正しいです、この正確なメモリアドレスは親に属しますが、IMOの説明ではっきりしているはずです。 – Maresh