I'm trying to multi-core read data from 2 files, but after executing this code list1
and list2
is empty.
from multiprocessing import Process
def getfile(fn, out):
print("start reading file {}".format(fn))
with open(fn) as file:
for line in file:
out.append(line)
if __name__ == '__main__':
file1 = []
file2 = []
p1 = Process(target=getfile, args=("100.txt", file1))
p2 = Process(target=getfile, args=("98.txt", file2))
p1.start()
p2.start()
p1.join()
p2.join()
print(file1)
print(file2)
How to get write data from files to list or something iterable using multiprocessing?