title: Write thread-safe to file in python
body: <p>How can I write data to a file in Python thread-safe? 
  I want to safe some variables to a file for every request and every hour I want to do some grouping and write it to mysql.</p>
  
  <p>In Java I now put it in an Array which is cached and this is written to a file when the array is full. </p>
  
  <p>How can I do this in Python? There are many concurrent requests so it has to be thread-safe.</p>
  
  <p>EDIT:</p>
  
  <p>We ended up using the logging module which works fine.</p>