Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python opened one file and is reading its data, why python still can read its data even I delete this file?

My python program is to read data from a txt file and insert data into my postgre database. The program has already started and keeps running. Then I accidently deleted the file on the disk, but the program still keeps running and inserting data into database.

Is that because when python open a file, it loads the file into memory, so that even I delete the file on the disk, it doesn't affect the running program? But my file is more than 3GB, does python really load my file into memory? I'm worrying about whether or not my data in database is correct.

Here is my code that opens the file:

f = open("/home/minjian/Documents/tweets2009-07.txt")

My operating system is:

Linux minjian-OptiPlex-9020 3.16.0-46-generic #62~14.04.1-Ubuntu SMP Tue Aug 11 16:27:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
like image 502
Minken Lau Avatar asked Apr 20 '26 03:04

Minken Lau


1 Answers

POSIX-compliant operating systems leave the actual file data on disk until all file handles are closed, even if there are no longer any links pointing to the data.

like image 65
Ignacio Vazquez-Abrams Avatar answered Apr 22 '26 15:04

Ignacio Vazquez-Abrams