title: Multiple threads writing to the same CSV in Python
body: <p>I'm new to multi-threading in Python and am currently writing a script that appends to a csv file. If I was to have multiple threads submitted to an <code>concurrent.futures.ThreadPoolExecutor</code> that appends lines to a csv file. What could I do to guarantee thread safety if appending was the only file-related operation being done by these threads?</p>
  
  <p>Simplified version of my code:</p>
  
  <pre><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)) 
  </code></pre>
  
  <p>And my thread class being:</p>
  
  <pre><code>def downloadThread(arguments......):
  
                  #Some code.....
  
                  writer.writerow(re.split(',', line.decode()))
  </code></pre>
  
  <p>Should I set up a seperate single-threaded executor to handle writing or is it woth worrying about if I am just appending?</p>
  
  <p>EDIT: I should elaborate that when the write operations occur can vary greatly with minutes between when the file is next appended to, I am just concerned that this scenario has not occurred when testing my script and I would prefer to be covered for that.</p>