1

file_a.py

while 1:
    print 1

When I remove, rename, even change "print 1" to "print 2", it is still running with printing 1.

Does it mean python runs with pyc files? What kind of feature of interpreter works here?

2
  • 2
    Even if it did use the raw source file, re-reading the file every time a line needed to be executed would be ridiculously slow. Commented Nov 25, 2013 at 3:11
  • It reads the file into memory once; it won't keep rereading the file if you change it. Commented Nov 25, 2013 at 3:20

1 Answer 1

2

You seem to misunderstand the execution process. With most conventional Python implementations, it essentially goes like this: your source file is compiled into bytecode, and that bytecode is run in a VM. Changing the source file after the fact has no bearing on code that is already running.

What you describe is a feature of some languages, however (e.g. Erlang). It's called hot swapping.

Sign up to request clarification or add additional context in comments.

2 Comments

I've heard that it can be a problem in bash, and that to avoid it you can wrap your code in braces to force bash to read it all before running it.
Thank you for your answer, so if i have a long-time python program, when i run it, there is no influence by editing its source code until i abort and rerun the python program again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.