424,279 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,279 IT Pros & Developers. It's quick & easy.

modify a long-running python script while it is running?

P: n/a
I often execute a long-running python script which is a "driver" for
my application; it may run for several hours on a large input.

Under CPython, is it safe for me to modify the Python script and run
it under some smaller inputs for test purposes, while the long-running
script is still running? It seems safe to do so, but I want to be
sure. I know, for example, that #!/bin/sh on my system is not safe in
this regard.

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?"[1]

Thank you,

Footnotes:
[1] how would I know that it is started? For example, at least one
print statement I am expecting has been executed.
--
Benjamin Rutt
Dec 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Benjamin Rutt <ru**@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?"[1]


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
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Dec 20 '05 #2

P: n/a
Kevin Yuan wrote:
I have a silly question: Can *VERY* large script cause memory overflow
if python load all the entire script file into memory?


If you have a script that is literally larger than memory, then what
else would happen but an overflow error of some kind?

What's the point of the question, really? You don't plan to load a
script that is larger than, say, 100K, do you? Maybe if you can
describe your real concern we can help better.

-Peter

Dec 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.