简体   繁体   中英

What happens when I modify the source code of a running python program?

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?

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 (eg Erlang). It's called hot swapping .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM