Andres Charles
Andres Charles

Reputation: 83

Using python, daemonizing a process

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?

Upvotes: 3

Views: 4630

Answers (2)

NPE
NPE

Reputation: 500883

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.

Upvotes: 5

JC Plessis
JC Plessis

Reputation: 693

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...

Upvotes: -3

Related Questions