python read file non blocking on windows

Viewed 3523

I have a programm on windows (Win7) that writes to a txt file every x seconds. Now I have a python script that reads this txt File every x seconds. When the python script reads the File and at the same time the other Program wants to write to that file - The writing program crashes (and displays permission error). Since I cant modify the way the Program writes to the txt file, I have to try to open the txt File without blocking the writing program. Does someone know what I could do in this situation (reading without blocking) I would be very happy for every tip on this topic!

The code for the Program that tries to read the File goes something like this:

    with codecs.open(datapath, "r", 'utf-16') as raw_data:

         raw_data_x = raw_data.readlines()

I have to open the File with "codecs" because its in unicode.

2 Answers
Related