Using python, daemonizing a process

雨燕双飞 提交于 2019-12-21 05:41:44

问题


Okay I have looked at python-daemon, and also at various other daemon related code recipes. Are there any 'hello world' tutorials out there that can help me get started using a python based daemonized process?


回答1:


The PEP 3143 contains several examples, the simplest one of which is:

import daemon

from spam import do_main_program

with daemon.DaemonContext():
    do_main_program()

This seems as straightforward as it gets. If there's something that's unclear, please pose specific questions.




回答2:


Using subprocess.Popen, you can launch another process that will survive your current process...

In a python console run :

import subprocess
subprocess.Popen(["/bin/sh", "-c", "sleep 500"])

Kill your console, look at existing processes, sleep is alive...



来源:https://stackoverflow.com/questions/7675573/using-python-daemonizing-a-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!