是否可以保存正在运行的程序并在下次重新加载? [英] Is it possible to save a running program and reload next time ?

查看:77
本文介绍了是否可以保存正在运行的程序并在下次重新加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个程序会继续运行好几天。当它运行时,我不能做什么,除非等待,因为它占用了银联时间的大部分时间。


是否有可能程序可以将所有正在运行的数据保存到文件中

我希望它停止,并且可以重新加载数据并继续运行

其中当电脑空闲时它会停止吗?


问候,


xiaojf

解决方案


fd ******** @ gmail.com 写道:





我有一个程序会继续运行几天。当它运行时,我不能做什么,除非等待,因为它占用了银联时间的大部分时间。


是否有可能程序可以将所有正在运行的数据保存到文件中

我希望它停止,并且可以重新加载数据并继续运行

其中当电脑空闲时它会停止吗?


问候,


xiaojf



你不能只用time.sleep把你的程序放进去,呃,睡觉吗?对于

的例子,time.sleep(10)将有效地暂停你的程序10 / b
秒,使得它使用很少的CPU周期。我不知道你有什么

界面,但假设你可以拿起一个按钮或一个按键

按,你可以要求一段时间,或者只需将你的代码放入

持有模式:


def pause():

暂停= True

暂停时:

time.sleep(1)

如果wake_up_key_pressed:

暂停= False


或gui:


暂停= False


def pause():

全球暂停

暂停=真实

暂停时:

time.sleep(1)


def onWakeUpButton():#bind this to button

全局暂停

暂停= False

Iain


fd********@gmail.com 写道:


是否有可能程序可以将所有正在运行的数据保存到文件中

我希望它停止,并且可以重新加载数据和孔蒂nue从

运行,当计算机空闲时它会停止吗?



这不是你要求的(我不知道怎么做),但

给出你的描述,也许一个不同的解决方案可行。


如果您使用的是* nix类型的操作系统(或者可能是Cygwin,从未尝试过),并且使用

bash-style shell,那么你可能已经内置了作业控件。

例如,在bash中你可以输入< CTRL> Z来停止当前进程,

你可以使用

''job''命令查看所有工作及其状态和工作号码,然后您可以使用'%[job_number]''恢复已停止的工作。

例如,如果他排队中只有一份工作,那就停下来然后当你准备好时再做
%1。


另一份* nix选项将使用nice命令设置进程的

调度优先级,以便当具有更高优先级
优先级的东西需要CPU时,它首先得到它而不是你的好'

进程(类似''nice -n 15 python your_program.py''应该做的事情

well - 非常低优先级)。我非常确定Windows还有一些优先选项可用于任务,事实上,IIRC你打开任务

经理并右键点击任务可以设置优先级更低。


问候,

Jordan


fd ******** @ gmail.com 写道:


我有一个程序将继续运行几天。当它运行时,我不能做什么,除非等待,因为它占用了银联时间的大部分时间。


是否有可能程序可以将所有正在运行的数据保存到文件中

我希望它停止,并且可以重新加载数据并继续运行

其中电脑空闲时它会停止吗?



对于Linux(以及其他类似Unix的操作系统),有几个checkpointing

库可用,它们可以将程序保存到磁盘,并重新启动

以后。


如果人们给你的其他建议(停止和继续

流程),或睡眠陈述,或保存状态,不要工作调查

这些。


例如 http://www.cs.wisc.edu/~zandy/ckpt /


这些程序对可以恢复的内容有限制(例如线程,

共享内存,网络连接......)。我不知道哪些可以使用

python。


-

Jeremy Sanders
http://www.jeremysanders.net/

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

解决方案


fd********@gmail.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_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


fd********@gmail.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


fd********@gmail.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 "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/


这篇关于是否可以保存正在运行的程序并在下次重新加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆