I am new to Python multithreading and am currently writing a script that joins a csv file. If I had several streams sent to concurrent.futures.ThreadPoolExecutor
, which adds lines to the csv file. What can I do to guarantee thread safety if adding was the only file-related operation performed by these threads?
A simplified version of my code:
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
for count,ad_id in enumerate(advertisers):
downloadFutures.append(executor.submit(downloadThread, arguments.....))
time.sleep(random.randint(1,3))
And my stream class:
def downloadThread(arguments......):
writer.writerow(re.split(',', line.decode()))
Should I set up a separate single-threaded artist to handle the recording, or worry if I just add?
EDIT: , , , , , , script, .