473,739 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Sep 21 '06 #1
14 3446

fd********@gmai l.com 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_pre ssed:
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

Sep 21 '06 #2
fd********@gmai l.com 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

Sep 21 '06 #3
fd********@gmai l.com 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 "checkpoint ing"
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/
Sep 21 '06 #4
On 2006-09-21, fd********@gmai l.com <fd********@gma il.comwrote:
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.co m/library/tpl/cgi-bin/getdoc.cgi?coll =0650&db=man&fn ame=/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// - mailto:ro****** ******@knapp.co m
Sep 21 '06 #5
Jeremy Sanders <je************ *******@jeremys anders.netwrote :
For Linux (and other Unix like OSs), there are several "checkpoint ing"
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.
Sep 21 '06 #6
Dennis Lee Bieber wrote:
On Thu, 21 Sep 2006 15:34:21 +0800, "fd********@gma il.com"
<fd********@gma il.comdeclaimed the following in comp.lang.pytho n:

>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

Sep 21 '06 #7
fd********@gmai l.com 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
Sep 21 '06 #8
fd********@gmai l.com 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

Sep 21 '06 #9
fd********@gmai l.com wrote:
>
Can objects be saved and reloaded by "Pickle" ? I have tried but no
success.
Yes, that's the intended use of pickle/cPickle. There are examples in
the docs:

http://docs.python.org/lib/module-pickle.html

What have you tried and what didn't work?

Hans Georg
Sep 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3223
by: ukjock | last post by:
I am very new to the whole Visual Basic .net scene, and I am trying to get to grips with it... I thought I would try and learn a programming language, and I was advised on vb.net. I have already come across my first problem, of saving a combobox. I want to save the contents of a combobox and the reload the contents when the form re-loads. Any advise and any great Idiots guide website's? Thanks for your help
7
2577
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently upgraded to VB.NET, and I have a lot of catching up to do. That being said, I have come a long way in a short while, however, I am stumped at the moment. I have read through days of posts, but have not been able to address my specific question, so...
6
6670
by: Stefan Mueller | last post by:
After my web page has been loaded I'm doing some tests with a JavaScript. If I figure out that something is wrong I'd like to reload the whole frameset. With Internet Explorer and Mozilla Firefox I can reload the whole frameset with parent.location.href = "index.html"; However, this doesn't work with Opera. Does someone know how to do that with Opera?
0
2184
by: noobcprogrammer | last post by:
#include "IndexADT.h" int IndexInit(IndexADT* word) { word->head = NULL; word->wordCount = 0; return 1; } int IndexCreate(IndexADT* wordList,char* argv)
32
1758
by: BillJosephson | last post by:
Hi, I want to write a program in Java or C++, and just discovered on my bookshelve Codewarrior 7. It says Windows 95, 98, NT, 2000, ME. Can I develop a command line application that will work on my XT machine? A grahpical interface? Thanks a lot for any thoughts on this. I know I should get a newer compiler but if I could save the money for the time being that would be great. Thanks.
3
1728
by: Ratko | last post by:
Hi all, I have a python gui app that launches multiple applications using subprocess.Popen class and prints their output in the gui (using PIPEs, threads and wxPython). Everything works great but the problem is that some applications should run in the background (ie they don't close when the gui closes) so next time when you start the gui it will not have a handle on those processes that are still running and therefore won't be able to...
3
1552
by: Stef Mientki | last post by:
hello, I've a graphical application (wxPython), where the code in the main GUI loop is given below. 1 JAL_Loaded = False 2 while len(App_Running) 0: 3 if JALsPy_globals.State == SS_Run: 4 try:
6
4157
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would try my own small program. The problem is, I seem to be having trouble with memory, i.e. sometimes my program will work and display the correct output, and sometimes it will not and display garbage (in a printf call) so i assume i have been using...
1
1393
by: coolsti | last post by:
Here is a strange occurrance: I start up my Visual C# 2008 Express program today, start a new project, put a bunch of controls on a form, save the project, and then close the program (for a break) and start it up again after. I reload my project, and it is empty. No form, no controls. I try again. And again. The same continues to happen. Anyone know what can be wrong? I did not register my Visual C# 2008 Express as it had been warning me...
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8794
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9483
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9269
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9211
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.