[英]How can I make a Python script keep running after I close my shell?
I've coded a Discord bot in Python. 我已经用Python编写了Discord机器人。 I have it hosted on a server that I use PuTTy to SSH into.
我将其托管在使用PuTTy SSH进入的服务器上。 Closing that terminal will obviously result in the bot ceasing to work.
关闭该终端显然会导致机器人停止工作。 Does Python have a process management system that will allow me to keep a Python script running?
Python是否具有可让我保持Python脚本运行的流程管理系统?
I'm running centOS. 我正在运行centOS。
It depends about how much experience you have programming in python. 这取决于您有多少使用python编程的经验。 For example you could use daemonize (which I personally prefer).
例如,您可以使用守护程序 (我个人更喜欢)。 And this is the simplest example available (from the daemonize documentation)
这是最简单的示例(来自守护程序文档)
from time import sleep
from daemonize import Daemonize
pid = "/tmp/test.pid"
def main():
while True:
sleep(5)
daemon = Daemonize(app="test_app", pid=pid, action=main)
daemon.start()
Another way to keep your script running, it could be install screen . 保持脚本运行的另一种方法是安装屏幕 。 Execute screen before executing your script and then detach the session using "Ctrl+a"+"d"
在执行脚本之前执行屏幕,然后使用“ Ctrl + a” +“ d”分离会话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.