I have a python function that read a file the way below:
def parse(filename, position): with open(filename,'r') as file: for index, line in enumerate(islice(file,position,None), 1): ... do something print line file.close() return index
This function is called every time another application, that is out of my control, write some data to the file, this way I try to avoid reading and write simultaneously, because I don't want the file to be corrupted. Anyway there is no guarantee read and write will not occur simultaneously.
What I already know is:
- If simultaneous read/write occur it is possible that reading function don't read the most updated information, like in this question, and that is fine for me because the purpose is to get information from file without corrupting it.
- It is possible to lock the file for reading so the writing application will not write while I read. But I don't need this because, as said, there is no problem in reading old data.
What I want to know is:
- Can this reading function, the way it is, corrupt the file?
- If no, what guarantee that file will not be corrupted?.
- There is any other possible problem/inconsistency in this read/write scenario?