README.rst 2.2 KB
Newer Older
1
daemonize
2 3
========================

4 5 6 7 8

.. image:: https://readthedocs.org/projects/daemonize/badge/?version=latest
    :target: http://daemonize.readthedocs.org/en/latest/?badge=latest
    :alt: Latest version

9
.. image:: https://img.shields.io/travis/thesharp/daemonize.svg
10 11 12
    :target: http://travis-ci.org/thesharp/daemonize
    :alt: Travis CI

13 14 15
.. image:: https://img.shields.io/pypi/dm/daemonize.svg
    :target: https://pypi.python.org/pypi/daemonize
    :alt: PyPI montly downloads
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30
.. image:: https://img.shields.io/pypi/v/daemonize.svg
    :target: https://pypi.python.org/pypi/daemonize
    :alt: PyPI last version available

.. image:: https://img.shields.io/pypi/l/daemonize.svg
    :target: https://pypi.python.org/pypi/daemonize
    :alt: PyPI license


**daemonize** is a library for writing system daemons in Python. It is
distributed under MIT license. Latest version can be downloaded from
`PyPI <https://pypi.python.org/pypi/daemonize>`__. Full documentation can
be found at
`ReadTheDocs <http://daemonize.readthedocs.org/en/latest/?badge=latest>`__.
31 32 33 34 35 36 37 38 39

Dependencies
------------

It is tested under following Python versions:

-  2.6
-  2.7
-  3.3
40
-  3.4
Ilya Otyutskiy's avatar
Ilya Otyutskiy committed
41
-  3.5
42 43 44 45 46 47 48 49 50 51 52 53 54

Installation
------------

You can install it from Python Package Index (PyPI):

::

    $ pip install daemonize

Usage
-----

55
.. code-block:: python
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

    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()

File descriptors
----------------

Daemonize object's constructor understands the optional argument
**keep\_fds** which contains a list of FDs which should not be closed.
For example:

77
.. code-block:: python
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    import logging
    from daemonize import Daemonize

    pid = "/tmp/test.pid"
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)
    logger.propagate = False
    fh = logging.FileHandler("/tmp/test.log", "w")
    fh.setLevel(logging.DEBUG)
    logger.addHandler(fh)
    keep_fds = [fh.stream.fileno()]


    def main():
        logger.debug("Test")

    daemon = Daemonize(app="test_app", pid=pid, action=main, keep_fds=keep_fds)
Ilya Otyutskiy's avatar
Ilya Otyutskiy committed
96
    daemon.start()