I am trying to read huge csv file and do some actions on it and store result of each processed row in a queue , I wrote code based on this answer on SO.
But unfortunately it is not working , any help will be appreciated.
Below is my code.
def process_line(drow):
print('sleeping')
sleep(10)
g_descript = drow['desc']
date_str = g_descript.split('—')
if len(date_str) > 1:
ndt = search_dates(date_str[0])
else:
ndt = None
drow['ndt'] = ndt
q.put(drow)
def get_n_line():
file_path = '/home/ztcUK.csv'
with open(file_path,'r') as f:
cdict = csv.DictReader(f)
for row in cdict:
yield row
if __name__ == '__main__':
f = get_n_line()
p = Pool(processes=10)
n = 0
for i in f:
n = n + 1
print(n)
p.map(process_line,(i,))
p.close()
p.join()
I expect 10 parallel threads running but only 1 is running , I put sleep for debugging purpose.
Below is the output.
