modify a long-running python script while it is running?
mwm at mired.org
Tue Dec 20 01:02:01 CET 2005
Benjamin Rutt <rutt at bmi.osu.edu> writes:
> I suppose this question could be reformatted as "does CPython read the
> entire script file into memory and then close the file before
> executing the script, making it safe for me to modify the script after
> I know it has started?"
Yes, but (didn't you expect that?) it loads imported files when it
first executes an import statement for them. Future import statements
will just get a reference to the loaded module, and won't reload
it. So after your application imports all the modules it needs, it
won't refer to the copies on disk again, after which it will be safe
for you to modify the on-disk copies.
Of course, you really ought to be working on a *copy* of the
application sources. When you're happy that your modifications are ok,
copy your development sources into production.
And finally, to force python to reload a module that it's already
loaded, use "reload(modulename)".
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list