Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Python's python-daemon and daemonize?

Tags:

python

pip

daemon

Both appear to be designed for the same purpose. Are both being updated? Which one should I use?

As a side note, what controls which packages are installed when you run pip install <packagename>? I ran pip install daemon and got the daemonize package, which was surprising because I was trying to install python-daemon. Later I ran pip install python-daemon and got it.

like image 444
Eli Rose Avatar asked Aug 01 '26 03:08

Eli Rose


1 Answers

As far as I can tell the main difference is that python-daemon is a reference implementation for PEP3143, which is a proposal to introduce a package to the standard library:

https://www.python.org/dev/peps/pep-3143/#reference-implementation

On the other hand the daemonize package is one of several 3rd party libraries that accomplish the same goal. From the documentation, it's basic usage is to create a main() function, then pass that as a parameter to a new instance of Daemonize and then call .start(), eg:

from time import sleep
from daemonize import Daemonize

pid = "/tmp/test.pid"


def main():
    while True:
        sleep(5)

daemon = Daemonize(app="test_app", pid=pid, action=main)
daemon.start()

[source: https://pypi.python.org/pypi/daemonize ]

Contrast this with python-daemon's basic usage, which uses a context manager (i.e. 'with' block) and you simply call the functions inside the context:

import daemon

from spam import do_main_program

with daemon.DaemonContext():
    do_main_program()

[source: https://www.python.org/dev/peps/pep-3143/#example-usage ]

like image 176
AcidReign Avatar answered Aug 03 '26 16:08

AcidReign



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!