Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > modify a long-running python script while it is running?

Reply
Thread Tools

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

 
 
Benjamin Rutt
Guest
Posts: n/a
 
      12-19-2005
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
 
Reply With Quote
 
 
 
 
Mike Meyer
Guest
Posts: n/a
 
      12-20-2005
Benjamin Rutt <(E-Mail Removed)> 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 <(E-Mail Removed)> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      12-20-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Block execution of script while same script is already running MrBanabas@googlemail.com Ruby 2 12-17-2008 06:03 PM
How to modify a program while it's running? Joe Strout Python 10 12-17-2008 07:34 AM
modify dictionary while iterating s99999999s2003@yahoo.com Python 5 11-11-2005 02:41 PM
how to modify code while debugging it without having to stop and then restart debugger python Python 13 11-10-2005 09:28 PM
Modify during a while statement mechanicscart@hotmail.com Perl Misc 3 09-03-2003 06:36 PM



Advertisments