在 Linux 中守护 python 脚本的最简单方法是什么?
在 Linux 中守护 python 脚本的最简单方法是什么? 我需要它适用于各种版本的 Linux,因此它应该只使用基于 python 的工具。
What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
nohup
以 Python 方式创建守护进程
nohup
Creating a daemon the Python way
我最近使用过 Turkmenbashi :
I have recently used Turkmenbashi :
使用 grizzled.os.daemonize:
了解其工作原理或自行操作,阅读有关 ActiveState 的讨论。
Use grizzled.os.daemonize:
To understand how this works or to do it yourself, read the discussion on ActiveState.
如果您不关心实际的讨论(这些讨论往往会偏离主题并且不提供权威的回应),您可以选择一些可以让您更轻松地品味的库。 我建议看一下 ll-xist,这个库包含大量拯救生命的代码,如 cron 作业助手、守护进程框架,以及(您对此不感兴趣,但确实很棒)面向对象的 XSL(ll-xist 本身)。
If you do not care for actual discussions (which tend to go offtopic and do not offer authoritative response), you can choose some library that will make your tast easier. I'd recomment taking a look at ll-xist, this library contains large amount of life-saving code, like cron jobs helper, daemon framework, and (what is not interesting to you, but is really great) object-oriented XSL (ll-xist itself).
请参阅 Stevens 以及此 关于 activestate 的冗长线程,我个人认为这大多是不正确的,而且非常冗长,我想出了这个:
如果您需要再次停止该进程,则这是必需的要了解 pid,通常的解决方案是 pidfiles。 如果您需要一个,请执行此操作
出于安全原因,您可以在妖魔化后考虑其中任何一个
您也可以使用 nohup 但这不适用于 python 的子进程模块
See Stevens and also this lengthy thread on activestate which I found personally to be both mostly incorrect and much to verbose, and I came up with this:
If you need to stop that process again, it is required to know the pid, the usual solution to this is pidfiles. Do this if you need one
For security reasons you might consider any of these after demonizing
You could also use nohup but that does not work well with python's subprocess module