关闭计算机时在服务器上执行代码

Executing a code on server while shutdown the computer

我有一个 python 代码,我想 运行 在 GPU 服务器上。 运行 这很耗时,有时,我会与 Internet 或服务器断开连接,我必须重新 运行 它。所以,我需要让它 运行 并关闭我的电脑。有什么办法吗?

如果它是 windows 服务器,则创建一个 bat 文件。 运行 python 脚本和关机命令。您必须是管理员才能通过脚本关闭计算机。

bat文件

c:\python27\python.exe c:\somescript.py %*

关机/s /f /t 0

您可以使用screen来维护一个会话并达到让您运行服务器上的代码的目的。

参考这个:https://www.gnu.org/software/screen/

一些基本命令:

  • 创建名为 RunWork 的会话
screen -S RunWork
  • 列出所有会话:
screen -ls
  • 打开会话
screen -r SessionID

...

如果你是 Linux 基础 OS 那么 Tmux 可以帮助你。

Tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

https://github.com/tmux/tmux/wiki