1

Let's say I have a python script called scr.py. Running python scr.py creates a scr.pyc file which is interpreted by Python. Now, let's say I make a change in scr.py while it is running, and then in another terminal window, I run python scr.py again. What happens? Does the original scr.pyc file get overwritten? Are there any problems that might occur? Could you run two slightly different copies of the same file at the same time?

u_ser722345
  • 639
  • 1
  • 6
  • 12
  • Are you asking for curiosity or is there a problem you are facing (for example, the script is taking a long time so you want to run it in parallel, by changing some things); or is the case that its a web application and you want to modify it without shutting down the server? – Burhan Khalid Apr 21 '14 at 16:08
  • Seems similar to [this question](http://stackoverflow.com/questions/11186600/modify-a-running-python-program). – Adam Apr 21 '14 at 16:08
  • 2
    Try it first with some simple code snippet and let us know what you got. :) – ρss Apr 21 '14 at 16:16

1 Answers1

0

Yes, it will try to overwrite .pyc file with the new version. But this won't affect the first program unless explicit module reload is called, in it because the module is loaded into memory.

OTOH, for example, printing stack for an exception needs reading source file, and, if it's changed, wrong lines will be printed. So this replacing on the fly is recommended only when module is properly reloaded just after this.

Netch
  • 4,171
  • 1
  • 19
  • 31