kten
kten

Reputation: 455

Python program is running even after the files are removed

It should sound stupid. But here is my scenario.

I have a python-flask website which is made live using nohup. Now even after i removed all files in __pycache__ and the original .py files the program is still running without any errors. So where does it run from ? Is there any cache of files getting created anywhere else?

Note: I know i can kill the process but just wanted to know about this issue

Upvotes: 0

Views: 851

Answers (2)

Eugene Yarmash
Eugene Yarmash

Reputation: 150111

So where does it run from ?

It runs from memory. Once your program has been compiled to byte code (or the byte code has been loaded from .pyc files), it is shipped off for execution to the Python Virtual Machine and the original source file is closed. Removing it doesn't affect the running process.

Upvotes: 1

mhawke
mhawke

Reputation: 87134

As long as one process has a file open, the file will remain available to that process. No other processes can open it, and its existence will not be visible with normal OS utilities, such as ls.

In the case of Python, I think that the compiled version of the script remains in memory. Removing it from the filesystem does nothing to change that.

So your flask app is not affected until it terminates, at which point the resident memory will be freed and any files that it held open will be removed by the OS.

Upvotes: 1

Related Questions