[英]In an Ubuntu terminal how can I keep a python program going?
I recently got my own VPS and intend to run my discord bot off of it. 我最近有自己的VPS,打算从中运行不和谐的bot。 However the main problem I am encountering is when the PuTTY session is closed then the program turns off even though the server remains on.
但是,我遇到的主要问题是关闭PuTTY会话时,即使服务器保持打开状态,程序也会关闭。
How can I make the program a process that stays on forever until I choose to end it? 在选择结束该程序之前,如何使该程序永久存在?
Since you are on ubuntu in a terminal window when you start the python program use the nohup command (man page synopsis): 由于您在启动python程序时位于终端窗口的ubuntu上,因此请使用nohup命令(手册页摘要):
nohup - run a command immune to hangups, with output to a non-tty nohup-运行不受挂断影响的命令,并输出到非tty
For example: 例如:
$ nohup /tmp/a.out /tmp/data
nohup: ignoring input and appending output to 'nohup.out'
$
You can run the any script files in background by giving ampersand (&) symbol at the end of file name in terminal. 通过在终端的文件名末尾提供“&”符号,可以在后台运行任何脚本文件。
Example: 例:
sudo filename.py &
This keeps on running even if you close the putty session. 即使您关闭腻子会话,它也可以继续运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.