Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is it possible to save a running program and reload next time ?

Reply
Thread Tools

Is it possible to save a running program and reload next time ?

 
 
fdu.xiaojf@gmail.com
Guest
Posts: n/a
 
      09-21-2006
Hi,

I have a program which will continue to run for several days. When it is
running, I can't do anything except waiting because it takes over most
of the CUP time.

Is it possible that the program can save all running data to a file when
I want it to stop, and can reload the data and continue to run from
where it stops when the computer is free ?

Regards,

xiaojf

 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      09-21-2006
On Thu, 21 Sep 2006 15:34:21 +0800, "(E-Mail Removed)"
<(E-Mail Removed)> declaimed the following in comp.lang.python:

>
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?
>

You'd have to write the code to save state, which means you'd have
to be at a known resumable point... I suspect that, if you're nested
into a recursive function, that will not be possible as you'd have to
recreate the calling stack along with populating all know data.

It should be pointed out that "chaos theory" sort of got its start
from an attempt at doing something similar -- saving a massive data
array for later reloading. It turns out the saved data didn't have the
full resolution of the computations, so the restart from the saved data
diverged rapidly from where the prior run had been heading. (As I
recall, it was a weather simulation in the late 60s early 70s, and the
data was saved in single-precision text format -- meaning round-off
errors on output/input; these days it would be the equivalent of the
losses inherent in doing a long computation in 80-bit IEEE, but saving
intermediates [for reload] in 64-bit IEEE).

The other option may not be available under most operating system...
Namely a snapshot of the entire "core" of memory, so you can restore the
machine /exactly/ to the state it had been at the time of the snapshot
(this would probably affect everything on the machine -- all other
programs, etc.)


Though if someone else have more information contradicting me, I'd
be happy to hear it... <G>
--
Wulfraed Dennis Lee Bieber KD6MOG
http://www.velocityreviews.com/forums/(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
 
Iain King
Guest
Posts: n/a
 
      09-21-2006

(E-Mail Removed) wrote:
> Hi,
>
> I have a program which will continue to run for several days. When it is
> running, I can't do anything except waiting because it takes over most
> of the CUP time.
>
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?
>
> Regards,
>
> xiaojf


Can't you just use time.sleep to put your program to, uh, sleep? For
example, time.sleep(10) will effectively pause your program for ten
seconds, making it use very few CPU cycles. I don't know what
interface you have, but assuming you can pick up a button or a key
press, you can ask for a length of time, or just put your code into a
holding pattern:

def pause():
paused = True
while paused:
time.sleep(1)
if wake_up_key_pressed:
paused = False

or with a gui:

paused = False

def pause():
global paused
paused = True
while paused:
time.sleep(1)

def onWakeUpButton(): #bind this to button
global paused
paused = False


Iain

 
Reply With Quote
 
MonkeeSage
Guest
Posts: n/a
 
      09-21-2006
(E-Mail Removed) wrote:
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?


This isn't what you asked for (I have no idea how to do that), but
given your description, perhaps a different solution would work.

If you're using a *nix type OS (or possibly Cygwin, never tried) with a
bash-style shell, then you probably already have job control built in.
For example, in bash you can type <CTRL>Z to stop the current process,
and you can see all jobs and their states and job numbers with the
'job' command, and you can resume a stopped job with '%[job_number]'.
So for example, if only one job is in he queue, just stop it and then
when you're ready do %1.

Another *nix option would be to use the nice command to set the
schedular priority of the process so that when something with a higher
priority needs the CPU then it gets it first rather than your nice'd
process (something like 'nice -n 15 python your_program.py' should do
well -- very low priority). I'm pretty sure windows has some kind of
priority option for tasks as well, in fact, IIRC you open the task
manager and right click on a task and can set the priority lower.

Regards,
Jordan

 
Reply With Quote
 
Jeremy Sanders
Guest
Posts: n/a
 
      09-21-2006
(E-Mail Removed) wrote:

> I have a program which will continue to run for several days. When it is
> running, I can't do anything except waiting because it takes over most
> of the CUP time.
>
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?


For Linux (and other Unix like OSs), there are several "checkpointing"
libraries available which allow programs to be saved to disk, and restarted
later.

If the other suggestions people have given to you (STOPping and CONTinuing
processes), or sleep statements, or saving state, don't work investigate
these.

e.g. http://www.cs.wisc.edu/~zandy/ckpt/

These programs have limitations on what can be restored (e.g. threads,
shared memory, network connections...). I don't know which ones work with
python.

--
Jeremy Sanders
http://www.jeremysanders.net/
 
Reply With Quote
 
Roland.Csaszar
Guest
Posts: n/a
 
      09-21-2006
On 2006-09-21, (E-Mail Removed) <(E-Mail Removed)> wrote:
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?


Well, on Irix you could use cpr
<http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=0650&db=man&fname=/usr/share/catman/u_man/cat1/cpr.z>
but i don't know if your OS supports a similar feature

--
Roland Csaszar ----------- \\\ /// -------------- +43 316 495 2129
Software Development ------ \\\ /// ----------- http://www.knapp.com
KNAPP Logistics Automation - \\V// - (E-Mail Removed)
 
Reply With Quote
 
Duncan Booth
Guest
Posts: n/a
 
      09-21-2006
Jeremy Sanders <(E-Mail Removed)> wrote:

> For Linux (and other Unix like OSs), there are several "checkpointing"
> libraries available which allow programs to be saved to disk, and
> restarted later.
>

Another option which will work on just about anything would be to run the
program in a vmware virtual machine. Then you can suspend or resume the
virtual machine whenever you wish.
 
Reply With Quote
 
fdu.xiaojf@gmail.com
Guest
Posts: n/a
 
      09-21-2006
Dennis Lee Bieber wrote:
> On Thu, 21 Sep 2006 15:34:21 +0800, "(E-Mail Removed)"
> <(E-Mail Removed)> declaimed the following in comp.lang.python:
>
>
>> Is it possible that the program can save all running data to a file when
>> I want it to stop, and can reload the data and continue to run from
>> where it stops when the computer is free ?
>>
>>

> You'd have to write the code to save state, which means you'd have
> to be at a known resumable point... I suspect that, if you're nested
> into a recursive function, that will not be possible as you'd have to
> recreate the calling stack along with populating all know data.
>
> It should be pointed out that "chaos theory" sort of got its start
> from an attempt at doing something similar -- saving a massive data
> array for later reloading. It turns out the saved data didn't have the
> full resolution of the computations, so the restart from the saved data
> diverged rapidly from where the prior run had been heading. (As I
> recall, it was a weather simulation in the late 60s early 70s, and the
> data was saved in single-precision text format -- meaning round-off
> errors on output/input; these days it would be the equivalent of the
> losses inherent in doing a long computation in 80-bit IEEE, but saving
> intermediates [for reload] in 64-bit IEEE).
>
> The other option may not be available under most operating system...
> Namely a snapshot of the entire "core" of memory, so you can restore the
> machine /exactly/ to the state it had been at the time of the snapshot
> (this would probably affect everything on the machine -- all other
> programs, etc.)
>
>
> Though if someone else have more information contradicting me, I'd
> be happy to hear it... <G>
>

Thank you all!

Can objects be saved and reloaded by "Pickle" ? I have tried but no
success.

One of my friends tell me that VMware can save the current state of a
virtual machine by suspending it, and can restore the identical state
later. When a virtual machine is suspended , a file with a .vmss
extension is created(about 20M), which contains the entire state of the
virtual machine. When you resume the virtual machine, its state is
restored from the .vmss file.

So can this method be implemented with python ?

I have another idea. When python is running, it uses about 10M memory.
So can I just save a copy of the memory used by python and restore it
later ?

Regards,

xiaojf

 
Reply With Quote
 
Larry Bates
Guest
Posts: n/a
 
      09-21-2006
(E-Mail Removed) wrote:
> Hi,
>
> I have a program which will continue to run for several days. When it is
> running, I can't do anything except waiting because it takes over most
> of the CUP time.
>
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?
>
> Regards,
>
> xiaojf
>

You can save the state of Python objects and reload them at a later time/date by
using Zope's ZODB.

http://www.zope.org/Wikis/ZODB/FrontPage

-Larry Bates
 
Reply With Quote
 
Larry Bates
Guest
Posts: n/a
 
      09-21-2006
(E-Mail Removed) wrote:
> Hi,
>
> I have a program which will continue to run for several days. When it is
> running, I can't do anything except waiting because it takes over most
> of the CUP time.
>
> Is it possible that the program can save all running data to a file when
> I want it to stop, and can reload the data and continue to run from
> where it stops when the computer is free ?
>
> Regards,
>
> xiaojf
>

You can save the state of Python objects and reload them at a later time/date by
using Zope's ZODB.

http://www.zope.org/Wikis/ZODB/FrontPage

-Larry Bates

 
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
JavaScript refresh: <a href="#" onClick="window.location.reload( true );">Reload</a> Joshua Beall HTML 26 06-29-2007 06:31 PM
problem with reload(sys) (doing reload on the sys module) gen_tricomi Python 2 05-23-2006 10:03 AM
Is there an SNMP equivalent to "Reload in [x]" / "Reload cancel" commands? steve.chambers@gmail.com Cisco 5 05-20-2006 04:06 AM
How to get and cancel the reload event (F5, Reload nutton, ...) within a browser Stefan Mueller Javascript 4 11-05-2005 06:09 PM
CurrentElement->next = CurrentElement->next->next (UNDEFINED?) Deniz Bahar C Programming 2 03-09-2005 12:45 AM



Advertisments