0
I’m trying to write csv files using a Thread for each file. Code iterates a list generated by groupby and calls a thread for each group.
Calling the function directly files are saved normally:
[save_csv(Uf[0]+'.csv', header, Uf[1]) for Uf in ufs]
Using Threads, files are saved only with the header, even if the function is run to the end
[threading. Thread(target=(save_csv), args=(Uf[0]+'.csv', header, Uf[1]). start() for Uf in ufs]
Function save_csv:
def save_csv(file, header, content):
with open(file, 'w', newline='', encoding='utf-8') as f:
writer = csv.DictWriter(f, delimiter=';', fieldnames=header)
writer.writeheader()
writer.writerows(list(map(vars, content)))
Is there a reason for this to happen?
Note: The code is using object orientation and threads as required by the exercise list.
Clarified the doubt, thank you very much!
– AugustoCorrea