Search code examples
pythonfile-ioabort

Will aborting a Python script corrupt file which is open for read?


If I run a python script (with Linux) which reads in a file (e.g.: with open(inputfile) as infi:): Will the file be in danger when I abort the script by pressing Ctrl C?


Solution

  • Probably not. It will release the file handle when the script stops running. Also you typically only have to worry about corrupting a file when you kill a script that is writing to the file, in case it is interrupted mid-write.