即使在我注销 SSH 后,如何在后台运行 Python 脚本? [英] How to run a Python script in the background even after I logout SSH?

查看:28
本文介绍了即使在我注销 SSH 后,如何在后台运行 Python 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Python 脚本 bgservice.py 并且我希望它一直运行,因为它是我构建的 Web 服务的一部分.即使在我注销 SSH 后,如何让它继续运行?

I have Python script bgservice.py and I want it to run all the time, because it is part of the web service I build. How can I make it run continuously even after I logout SSH?

推荐答案

运行 nohup python bgservice.py & 使脚本忽略挂断信号并继续运行.输出将放入 nohup.out.

Run nohup python bgservice.py & to get the script to ignore the hangup signal and keep running. Output will be put in nohup.out.

理想情况下,您应该使用类似 supervise 以便它在(何时)死亡时可以重新启动.

Ideally, you'd run your script with something like supervise so that it can be restarted if (when) it dies.

这篇关于即使在我注销 SSH 后,如何在后台运行 Python 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆