gpt4 book ai didi

python - 如何在 Ubuntu 中分离进程

转载 作者:行者123 更新时间:2023-12-04 19:05:57 24 4
gpt4 key购买 nike

我在 Amazon EC2 实例上的 Ubuntu 服务器上运行聊天机器人。即使关闭 pUTTY 窗口,我也希望能够运行 python3 程序。到目前为止,我已经尝试过 'Ctrl+a, d' 以及 'Ctrl+z, bg'。然而,在关闭 pUTTY 窗口后,这两种方法似乎都不起作用。我引用了以下 youtube 视频:
非常感谢任何帮助!
Chatbot Output
Ubuntu Screen running python program

最佳答案

我希望问题是“即使在关闭腻子后如何保持 python 脚本运行”
IMO,您可以在此处使用 2 种方法。
使用 nohup
unix 命令 nohup即使退出终端,也可以让你的程序在后台运行。
你可以像这样运行它

nohup python3 LP_poolVol.py > /dev/null &
nohup将使脚本运行, &最后会成功的
背景
使脚本成为服务
将脚本作为 linux 服务运行,您可以使用 systemctl 启动和停止它。
您可以创建服务描述 rune 件 pool-vol.service内容与下面类似。
[Unit]
Description=Pool Vol Service
After=multi-user.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 <path-to>/LP_poolVol.py

[Install]
WantedBy=multi-user.target
然后将此服务文件复制到 /etc/systemd/system/ .然后通过下面的命令安装它
sudo systemctl daemon-reload
sudo systemctl enable pool-vol.service
sudo systemctl start pool-vol
现在您的应用程序作为服务运行。您可以使用 systemctl 停止或重新启动它。本身喜欢
sudo systemctl start pool-vol

关于python - 如何在 Ubuntu 中分离进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69551596/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com