Sanket Deshmukh
Sanket Deshmukh

Reputation: 186

Python IO - Is it safe to read a text file in python while other program is writing to it?

I want to read contents of a text file that is continuously being written by another program. How safe it is to read contents of that file. Will it corrupt the text file?

Upvotes: 3

Views: 457

Answers (1)

Michael Butscher
Michael Butscher

Reputation: 10969

Reading a text file doesn't corrupt it.

There can be access errors if the writing program doesn't keep the file open all the time and tries to open the file while it is read or the reading program can't open it while it is opened by the writing program.

If this happens depends on some settings (exclusive lock, shared lock) when opening the file and on the operating system. But the file itself won't be corrupted in any case.

Upvotes: 4

Related Questions