title: PermissionError [Errno 13] when writing to a file after using lockfile in python
body: <p>I would like to safely open and write to a file, so I decided to use the fileLock python library. This is my code:</p>
  
  <pre><code>            with filelock.FileLock('../rsc/datasets/train/' + server_predict.remove_special_chars(str(id_park)) + '.csv'):
                  with open('../rsc/datasets/train/' + server_predict.remove_special_chars(str(id_park)) + '.csv', mode='a') as file:
                      for line in data_by_id.values:
                          a = "\"" + server_predict.remove_special_chars(str(line[0])) + "\",\"" + str(line[1]) + "\"," + str(line[2]) #+ "\n"
                          file.write(a)
  </code></pre>
  
  <p>However, this raises a PermissionError exception, sometimes on the  </p>
  
  <blockquote>
    <p>file.write(a) </p>
  </blockquote>
  
  <p>line and others in the line </p>
  
  <blockquote>
    <p>for line in data_by_id.values </p>
  </blockquote>
  
  <p>Any clue where this error might come from? Is it me that I do not understand how fileLock works??</p>
  
  <p>Thanks!</p>