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

Discussion in 'Python' started by Benjamin Rutt, Dec 19, 2005.

  1. 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
    Benjamin Rutt, Dec 19, 2005
    #1
    1. Advertising

  2. Benjamin Rutt

    Mike Meyer Guest

    Benjamin Rutt <> 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 <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
    Mike Meyer, Dec 20, 2005
    #2
    1. Advertising

  3. Benjamin Rutt

    Peter Hansen Guest

    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
    Peter Hansen, Dec 20, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    672
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,184
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    471
    santosh
    Jul 24, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    796
    Peter Nilsson
    Jan 15, 2008
  5. veryhotsausage
    Replies:
    1
    Views:
    1,796
    veryhotsausage
    Jul 4, 2008
Loading...

Share This Page