简体   繁体   English

在Ubuntu终端中,如何保持python程序运行?

[英]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.

相关问题 如何使用pip在Ubuntu终端中pip安装Python 3? - How can I use pip to pip install Python 3 in Ubuntu terminal? 我如何从Mac终端执行此python程序 - How can I execute this python program from mac terminal Python,如何在捕获异常后使程序继续运行 - Python, how to keep program going after exception is caught Ubuntu 12.04如何在终端中运行Python 3.3.2程序 - Ubuntu 12.04 How To Run Python 3.3.2 Program In Terminal 如何在 ubuntu 启动时使用终端窗口启动 python 程序 - How to start python program with a terminal window on ubuntu startup 如何让 Python 程序从终端连续运行(直到我手动停止它)? - How can I make a Python program run continuously from the Terminal (until I stop it manually)? 如何在Macbook终端中运行Client-Server python程序? - How can I run Client-Server python program in macbook terminal? 如何使用 Python 程序向终端发送键盘中断 ctrl+]? - How can I send a keyboard interrupt ctrl+] to the terminal using a Python program? 如何通过 Python 程序以该用户身份切换用户并执行多个终端命令 - How can I switch user and perform multiple terminal commands as that user through a Python program 我可以在正在运行的Python程序中放置一个断点,该程序可以放到交互式终端吗? - Can I put a breakpoint in a running Python program that drops to the interactive terminal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM