473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
2 15028
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Markus Dehmann | last post by:
I guess this is a kind of newbie question (since most pointer questions are newbie questions). In the program below, modify(string* s) is supposed to change the content that s points to. But the...
28
by: Charles Sullivan | last post by:
I'm working on a program which has a "tree" of command line arguments, i.e., myprogram level1 ]] such that there can be more than one level2 argument for each level1 argument and more than one...
12
by: Michael B Allen | last post by:
Is it legit to modify static data like the following code? #include <stdlib.h> #include <stdio.h> struct tbl { int i; char *s; };
4
by: Vladimir C. | last post by:
Hashtable map = new Hashtable(); map = 10; map = 20; foreach(DictionaryEntry e in map) { e.Value = 100; Console.WriteLine("{0}: {1}", key, map); }
12
by: SStory | last post by:
Doing pages for contract..... If I make an ASPX file that does certain things, how simple would it be for a person who know nothing about it to modify the user interface without bothering the...
2
by: A. Farber | last post by:
Hello, I'm programming a web application and for that I'm trying to extend the standard C string functions, so that they can handle the application/x-www-form-urlencoded format (which encodes...
4
by: lesperancer | last post by:
it looks like this will save many versions of a relationship window, but based on the fact that the same tables are displayed in the relationship window and it will restore versions of what was...
7
by: Frank | last post by:
Years ago I wrote a program to read .lnk files, modify the data and rewrite the file. I modified it slightly and used it for .pif files. I can't find it nor can I find the API calls I used. ...
7
by: Boki | last post by:
Hi All, I want to change WindowState of form1 from form2. I tried these two methods, but no luck on both. (1) Declare a public method: /* function of form1 */ public void...
2
by: DotNetNewbie | last post by:
Hello, I have a regex and I want to modify the value of a named capture before doing the regex.Replace. So something like: string text = Regex.Replace(oldText, myRegex, @"<a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.