How do you lock a CSV file when writing to it using python

Viewed 1801

I'm using a Queue and threads to write data to a CSV. I'm running into a problem where one worker will be writing to the CSV, and then another will write to the CSV, causing issues in how the data is laid out.

Is it possible to lock the CSV when one worker opens it, so that no other worker can open it until they have closed it again?

Thanks!

1 Answers
Related