每24小时安排一次python执行

问题描述

我正在我的大学的服务器上训练几个神经网络。由于所有学生的资源有限,因此有一个名为(Slurm)的作业调度系统,该系统将所有学生的跑步排队,此外,我们只能在有时间限制(24h)的情况下运行命令。一旦超过了此处理时间,我们的运行过程就会关闭,以使其他人可以使用资源。

具体来说,我正在训练GAN,并且比24小时需要更多的训练时间。 现在,我正在保存模型的检查点,以在流程关闭之前从同一训练点重新开始。但是,我必须在24小时后再次执行相同的命令。

因此,我想每24小时自动安排一次执行

当前,我正在使用'tmux'执行命令并能够关闭终端。

关于如何使这种执行自动化的一些建议?

提前谢谢!

解决方法

您可以将作业设置为在接近时限时自动重新提交。

请注意,slurm的时间间隔为1分钟,因此请不要设置 信号计时器的时间少于60秒。

#!/bin/bash
#SBATCH --signal=B:USR1@300  # Tell Slurm to send signal USR1 300 seconds before timelimit 
#SBATCH -t 24:00:00
resubmit() {
  echo "It's time to resubmit";  # <----- Run whatever is necessary. Ideally resubmit the job using the checkpointing files
  sbatch ...
}

trap "resubmit" USR1 # Register signal handler

YOUR_TRAINING_COMMAND & # It's important to run on the background otherwise bash will not process the signal until this command finishes 

wait  # wait until all the background processes are finished. If a signal is received this will stop,process the signal and finish the script.

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...