-7

I have an extreme problem. I use replit as my IDE AND I accidently deleted my python script. It is serving a flask app that has launched 3 child processes. Can I get the code of the file while it's still running? I have no backups. I have written a lot of code that I don't want to lose. I am using ubuntu.

I have not tried anything yet.

davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

0

If you are using any type of Unix (you are), then the answer may be yes. (But see last paragraph.)

Files are not deleted when you remove the directory entry. They are only deleted when there are zero directory entries, and zero processes with the file open.

So how to access it.

On Gnu/Linux systems there is a proc directory. This directory has a sub-directory for each process.

  • Get the process ID of the desired process.
  • cd /proc/«process-id»/fd
  • ls -l
  • play guess the file, it will be one of these (usually not many).

This will only work if Python keeps the file open. (I just tested. It works for Bash, but I can't get this to work for Python. It looks like Python closes the file.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
  • Indeed, the Python interpreter reads the script into memory and compiles it into an internal representation at startup. So really, in this specific case, the answer is simply no. – tripleee Jun 05 '22 at 10:07